Basic Usage
A simple description of the usage of Instant.
Importing Instant
Edit your pubspec.yaml to include the latest version of Instant:
packages:
instant: ^0.1.1Then, run pub packages get:
$ pub packages getLastly, import Instant in the desired file's header:
import 'pacakges:instant/instant.dart';Using Instant
Instant revolves around the Dart class of DateTime. If you don't have a decent knowledge of this class yet, you probably want to read up; we'll be using it in a minute to get going.
Now, Instant has three main branches (timezones, times, and dates); they're all interrelated and very closely tied together. The basic usage is demonstrated below:
import 'pacakges:instant/instant.dart';
DateTime SanFran = curDateTimeByZone(zone: "PDT"); //current DateTime in PDT timezone
print(formatTime(time: SanFran)); //prints current time in PDT
print(formatDate(date: SanFran)); //prints current date in PDT
Easy, right? This would take you much longer traditionally, and might force you to create helper functions, integrate them, etc.
This is just the start of Instant's power. Let's take a closer look at each of the three lines above.
All four of the above options are completely valid and will be accepted by Instant's other methods. You can mix and match, depending on your needs, helping you integrate to whatever extent you want.
Pay particular attention to the last edit. The format field is extremely modular. You can use the chunks "HH" (hours), "MM" (minutes), "SS" (seconds), and "III" (milliseconds) in any order with any combination, leaving as many out as you like. As long as they are in a String with only those components, the program will figure it out.
Again, pay attention to the last edit. You can again use the chunks "YY" (years-2), "YYYY" (years-4), "MM" (months), and "DD" (days) in any order with any combination, leaving as many out as you like. As long as they are in a String with only those components, the program will figure it out.
The above is a pretty good summary of the basics of Instant. However, there's a lot more to go over beyond these three functions. Make sure to check out Advanced Usage to see how to use all of Instant's features.
Last updated
Was this helpful?