moment_dart는 Flutter 애플리케이션에서 날짜 및 시간 조작을 쉽게 하기 위해 설계된 다목적이고 불변의 DateTime 서브클래스입니다. 여러 지역화를 지원하여 개발자가 DateTime 및 Duration 객체를 다양한 언어와 지역에 맞춰 인간이 읽기 쉬운 형식으로 변환할 수 있게 해줍니다. 불변성을 중심으로 설계되어 안전하고 예측 가능한 상태 관리를 보장합니다. 이 패키지는 Android, iOS, Web, macOS, Windows, Linux 플랫폼과 원활하게 통합되며, 강력한 날짜 포맷팅 및 지역화 기능을 필요로 하는 크로스플랫폼 앱에 이상적입니다.
// 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