Getting Started ✨
moment_dart is a moment.js inspired
DateTime
query,
manipulation, and humanization library for Dart.
tip
Moment
extends DateTime
, and is immutable.
final now = Moment.now();
assert(now is DateTime); // true
assert(now is Moment); // true
Installation
In your project directory, run:
dart pub add moment_dart
# For flutter
flutter pub add moment_dart
or, manually add in pubspec.yaml
pubspec.yaml
...
dependencies:
moment_dart: 2.2.0
...
Usage
-
Import the package
import 'package:moment_dart/moment_dart.dart';
You may want to set global localization at the initialization of your application.
-
Create a moment instance. See list of constructors
Moment moment = DateTime.now().toMoment();
You can also use static methods such as
Moment.startOfToday()
Moment.endOfNextIsoWeek()
Common problems you might face
Like DateTime
, most functionality in moment_dart does not check, enforce,
or alter the timezone of date times. Altough, Some methods like
Moment.format()
do offer options to enforce certain timezone.
You might want to skim through common mishaps.