// From DateTimefinal a = DateTime.now().toMoment();
final b = Moment(DateTime(...));
// This instance won't be affected by global localization!final c = Moment(b, localization: MomentLocalizations.koKr());
final yesterday = Moment.now() - constDuration(days: 1);
yesterday.fromNow(); // a day agofinal add5sec = Moment.now().add(constDuration(seconds: 5));
add5sec.fromNow(dropPrefixOrSuffix: true); // a few seconds
Precise duration
You can create localized human-readable duration text with
abbreviation, highly-customizable units.
See more on docs.
(delimiter, custom units, abbreviation...)
final epoch = Moment.fromMillisecondsSinceEpoch(0);
final now = DateTime(2023, DateTime.july, 14).toMoment();
print(epoch.fromPrecise(now)); // 53 years 7 months ago
Calendar
finalMoment now = Moment.now();
print(now.calendar()); // Today at 03:00 PM
Other helpful methods
moment_dart provides numerous convenience methods. Works on both Moment and DateTime.
final now = DateTime.now(); // July 19 2023 03:12 PM (UTC+8)// ISO week, ISO week year
now.week; // 48
now.weekYear; // 2023
now.isLeapYear; // false// Date creates new `DateTime` with hours, minutes, etc.. omitted
now.date; // July 19 2023 00:00 AM
now.clone(); // July 19 2023 03:12 PM
now.nextTuesday(); // July 25 2023 03:12 PM// and many more!
Contributing
Contributions of any kind are welcome! Please refer to CONTRIBUTE.md