Skip to main content
Version: 2.0.2

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.0.2
...

Usage

  1. Import the package

    import 'package:moment_dart/moment_dart.dart';

    You may want to set global localization at the initialization of your application.

  2. 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()

    See list of static methods

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.