Skip to main content
Version: 1.1.1

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: 1.1.1
...

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();

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.