Moment class

A subclass of DateTime. Therefore:

Moment.now() is DateTime == true // always

Set a global localization:

Global localizations will affect all moment instances, except those with explicitly set localizations.

Moment.setGlobalLocalization(MomentLocalizations.fr());

An instance with explicit localization:

Moment.now(localization: MomentLocalizations.mn())

Formatting

Moment().format will format DateTime based on the payload. For example:

Moment.fromMillisecondsSinceEpoch(0, isUtc: true).LLLL; // Thursday, January 1 1970 00:00 AM

See FormatterTokens

Inheritance
Available extensions

Constructors

Moment(DateTime dateTime, {MomentLocalization? localization})
A Moment created using given dateTime;
Moment.fromMicrosecondsSinceEpoch(int microsecondsSinceEpoch, {bool isUtc = false, MomentLocalization? localization})
Moment.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, {bool isUtc = false, MomentLocalization? localization})
Moment.now({MomentLocalization? localization})
A Moment created using DateTime.now(), in Local timezone
Moment.nowWithTimezone(bool isUtc, {MomentLocalization? localization})
factory

Properties

date DateTime

Available on DateTime, provided by the MomentBenefits extension

Returns new DateTime with the date at 00:00:00 AM, preserves timezone
no setter
date Moment

Available on Moment, provided by the MomentBenefitsPlus extension

no setter
day int
The day of the month [1..31].
no setterinherited
dayOfYear int

Available on DateTime, provided by the MomentBenefits extension

Returns ordinal day of the year in the current timezone
no setter
forcedSuperType DateTime

Available on Moment, provided by the MomentBenefitsPlus extension

Returns this as DateTime (the super type)
no setter
hasExplicitLocalization bool
no setter
hashCode int
The hash code for this object.
no setterinherited
hour int
The hour of the day, expressed as in a 24-hour clock [0..23].
no setterinherited
hour12 int

Available on DateTime, provided by the MomentBenefits extension

Returns hour in 12-hour format
no setter
isAm bool

Available on DateTime, provided by the MomentBenefits extension

Returns whether the hour is before noon (ante meridiem) in the current timezone
no setter
isFuture bool

Available on DateTime, provided by the MomentBenefits extension

no setter
isLeapYear bool

Available on DateTime, provided by the MomentBenefits extension

Returns if year is leap year.
no setter
isPast bool

Available on DateTime, provided by the MomentBenefits extension

no setter
isPm bool

Available on DateTime, provided by the MomentBenefits extension

Returns whether the hour is after noon (post meridiem) in the current timezone
no setter
isUtc bool
True if this DateTime is set to UTC time.
finalinherited
LL String
no setter
ll String
no setter
LLL String
no setter
lll String
no setter
LLLL String
no setter
llll String
no setter
localization MomentLocalization
Returns localization of this instance. If this doesn't have localization, returns the global localization.
no setter
LT String
no setter
LTS String
no setter
microsecond int
The microsecond [0...999].
no setterinherited
microsecondsSinceEpoch int
The number of microseconds since the "Unix epoch" 1970-01-01T00:00:00Z (UTC).
no setterinherited
millisecond int
The millisecond [0...999].
no setterinherited
millisecondsSinceEpoch int
The number of milliseconds since the "Unix epoch" 1970-01-01T00:00:00Z (UTC).
no setterinherited
minute int
The minute [0...59].
no setterinherited
month int
The month [1..12].
no setterinherited
quarter int

Available on DateTime, provided by the MomentBenefits extension

Returns quarter of the year.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
second int
The second [0...59].
no setterinherited
setLocalization MomentLocalization?
Original localization of this instance
no setter
timeZoneName String
The time zone name.
no setterinherited
timeZoneOffset Duration
The time zone offset, which is the difference between local time and UTC.
no setterinherited
week int

Available on DateTime, provided by the MomentBenefits extension

Returns ISO week number of the year
no setter
weekday int
The day of the week monday..sunday.
no setterinherited
weekYear int

Available on DateTime, provided by the MomentBenefits extension

Returns year according to ISO week number of the year
no setter
year int
The year.
no setterinherited

Methods

add(Duration duration) Moment
Returns new Moment with added duration
override
calendar({DateTime? reference, bool omitHours = false, String? customFormat}) String
Returns calendar string in accordance with the reference, such as Yesterday, Last Sunday, or default date format concatenated with default hour format. Default formats are derived from the current localization.
clone() DateTime

Available on DateTime, provided by the MomentBenefits extension

Returns new DateTime, preserves timezone
clone() Moment

Available on Moment, provided by the MomentBenefitsPlus extension

compareTo(DateTime other) int
Compares this DateTime object to other, returning zero if the values are equal.
inherited
copyWith({DateTime? dateTime, MomentLocalization? localization}) Moment
Returns new Moment with new values
copyWith({int? year, int? month, int? day, int? hour, int? minute, int? second, int? millisecond, int? microsecond, bool? isUtc}) DateTime

Available on DateTime, provided by the DateTimeCopyWith extension

Creates a new DateTime from this one by updating individual properties.
difference(DateTime other) Duration
Returns a Duration with the difference when subtracting other from this DateTime.
inherited
differenceInDays(DateTime other) int

Available on DateTime, provided by the MomentBenefits extension

Difference calculated after omitting hour, minute, ..., microsecond
endOf(DurationUnit unit) DateTime

Available on DateTime, provided by the EndOfUnit extension

Returned object will have same timezone as this
endOf(DurationUnit unit) Moment

Available on Moment, provided by the EndOfUnitMoment extension

Returned object will have same timezone as this
endOfDay() Moment

Available on Moment, provided by the EndOfUnitMoment extension

Returns end of the day
endOfDay() DateTime

Available on DateTime, provided by the EndOfUnit extension

Returns end of the day
endOfHour() Moment

Available on Moment, provided by the EndOfUnitMoment extension

Returns end of the hour
endOfHour() DateTime

Available on DateTime, provided by the EndOfUnit extension

Returns end of the hour
endOfLocalWeek([int? weekStart]) Moment

Available on Moment, provided by the EndOfUnitMoment extension

Returns end of the week based on localization.weekStart. You can override this with weekStart
endOfLocalWeek([int? weekStart]) DateTime

Available on DateTime, provided by the EndOfUnit extension

Returns start of the week based on weekStart. If it's null, it uses Moment.defaultLocalization.weekStart
endOfMillisecond() DateTime

Available on DateTime, provided by the EndOfUnit extension

Returns end of the millisecond
endOfMillisecond() Moment

Available on Moment, provided by the EndOfUnitMoment extension

Returns end of the millisecond
endOfMinute() Moment

Available on Moment, provided by the EndOfUnitMoment extension

Returns end of the minute
endOfMinute() DateTime

Available on DateTime, provided by the EndOfUnit extension

Returns end of the minute
endOfMonth() Moment

Available on Moment, provided by the EndOfUnitMoment extension

Returns end of the month
endOfMonth() DateTime

Available on DateTime, provided by the EndOfUnit extension

Returns end of the month
endOfSecond() DateTime

Available on DateTime, provided by the EndOfUnit extension

Returns end of the second
endOfSecond() Moment

Available on Moment, provided by the EndOfUnitMoment extension

Returns end of the second
endOfYear() DateTime

Available on DateTime, provided by the EndOfUnit extension

Returns end of the year
endOfYear() Moment

Available on Moment, provided by the EndOfUnitMoment extension

Returns end of the year
format([String payload = MomentLocalization.localizationDefaultDateFormat, bool forceLocal = false]) String
Formats date according to payload. See also: FormatterToken
format({String payload = MomentLocalization.localizationDefaultDateFormat, bool forceLocal = false, MomentLocalization? localization}) String

Available on DateTime, provided by the MomentBenefits extension

formatDate([bool forceLocal = false]) String
Localization Default formatters
formatDateShort([bool forceLocal = false]) String
formatDateTime([bool forceLocal = false]) String
formatDateTimeShort([bool forceLocal = false]) String
formatDateTimeWithWeekday([bool forceLocal = false]) String
formatDateTimeWithWeekdayShort([bool forceLocal = false]) String
formatTime([bool forceLocal = false]) String
formatTimeWithSeconds([bool forceLocal = false]) String
from(DateTime anchor, {bool dropPrefixOrSuffix = false, Abbreviation form = Abbreviation.none}) String
This will not return precise duration. See MomentLocalization.relativeThreshold for details
fromNow({bool dropPrefixOrSuffix = false, Abbreviation form = Abbreviation.none}) String
Example when using LocalizationEnUs:
fromNowPrecise({bool round = true, bool omitZeros = true, bool includeWeeks = true, Abbreviation form = Abbreviation.none, String? delimiter, DurationFormat format = DurationFormat.auto, bool dropPrefixOrSuffix = false}) String
Example when using LocalizationEnUs:
fromPrecise(DateTime anchor, {bool round = true, bool omitZeros = true, bool includeWeeks = true, Abbreviation form = Abbreviation.none, String? delimiter, DurationFormat format = DurationFormat.auto, bool dropPrefixOrSuffix = false}) String
This will return precise durations. For imprecise durations, use from()
isAfter(DateTime other) bool
Whether this DateTime occurs after other.
inherited
isAtSameDayAs(DateTime other, {bool enforceUTC = false}) bool

Available on DateTime, provided by the UnitComparision extension

Returns if two dates are in same day, month, year.
isAtSameHourAs(DateTime other, {bool enforceUTC = false}) bool

Available on DateTime, provided by the UnitComparision extension

Returns if two dates are in same hour, day, month, year.
isAtSameMicrosecondAs(DateTime other, {bool enforceUTC = false}) bool

Available on DateTime, provided by the UnitComparision extension

Returns if two dates are in same microsecond, millisecond, second, minute, hour, day, month, year.
isAtSameMillisecondAs(DateTime other, {bool enforceUTC = false}) bool

Available on DateTime, provided by the UnitComparision extension

Returns if two dates are in same millisecond, second, minute, hour, day, month, year.
isAtSameMinuteAs(DateTime other, {bool enforceUTC = false}) bool

Available on DateTime, provided by the UnitComparision extension

Returns if two dates are in same minute, hour, day, month, year.
isAtSameMomentAs(DateTime other) bool
Whether this DateTime occurs at the same moment as other.
inherited
isAtSameMonthAs(DateTime other, {bool enforceUTC = false}) bool

Available on DateTime, provided by the UnitComparision extension

Returns if two dates are in same month, year.
isAtSameSecondAs(DateTime other, {bool enforceUTC = false}) bool

Available on DateTime, provided by the UnitComparision extension

Returns if two dates are in same second, minute, hour, day, month, year.
isAtSameYearAs(DateTime other, {bool enforceUTC = false}) bool

Available on DateTime, provided by the UnitComparision extension

Returns if two dates are in same year.
isBefore(DateTime other) bool
Whether this DateTime occurs before other.
inherited
isFutureAnchored([DateTime? anchor]) bool

Available on DateTime, provided by the MomentBenefits extension

isPastAnchored([DateTime? anchor]) bool

Available on DateTime, provided by the MomentBenefits extension

isSameLocalWeekAs(DateTime other) bool

Available on Moment, provided by the UnitComparisonMoment extension

Returns whether this and other is in same local week. Local week is determined by localization.weekStart, defaults to DateTime.monday
isSameLocalWeekAs(DateTime other, [int? weekStart]) bool

Available on DateTime, provided by the UnitComparision extension

Returns whether this and other is in same local week. Local week is determined by weekStart, defaults to DateTime.monday
lastFriday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Friday in the past
lastFriday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Friday in the past
lastMonday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Monday in the past
lastMonday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Monday in the past
lastSaturday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Saturday in the past
lastSaturday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Saturday in the past
lastSunday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Sunday in the past
lastSunday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Sunday in the past
lastThursday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Thursday in the past
lastThursday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Thursday in the past
lastTuesday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Tuesday in the past
lastTuesday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Tuesday in the past
lastWednesday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Wednesday in the past
lastWednesday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Wednesday in the past
lastWeekday(int weekday) DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of last nth weekday
lastWeekday(int weekday) Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of last nth weekday
nextFriday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Friday in the Future
nextFriday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Friday in the Future
nextMonday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Monday in the Future
nextMonday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Monday in the Future
nextSaturday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Saturday in the Future
nextSaturday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Saturday in the Future
nextSunday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Sunday in the Future
nextSunday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Sunday in the Future
nextThursday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Thursday in the Future
nextThursday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Thursday in the Future
nextTuesday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Tuesday in the Future
nextTuesday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Tuesday in the Future
nextWednesday() DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest Wednesday in the Future
nextWednesday() Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest Wednesday in the Future
nextWeekday(int weekday) DateTime

Available on DateTime, provided by the WeekdayFinder extension

Returns new DateTime instance of nearest nth weekday in the future
nextWeekday(int weekday) Moment

Available on Moment, provided by the WeekdayFinderMoment extension

Returns new Moment instance of nearest nth weekday in the future
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
startOf(DurationUnit unit) Moment

Available on Moment, provided by the StartOfUnitMoment extension

Returned object will have same timezone as this
startOf(DurationUnit unit) DateTime

Available on DateTime, provided by the StartOfUnit extension

Returned object will have same timezone as this
startOfDay() Moment

Available on Moment, provided by the StartOfUnitMoment extension

Returns start of the day
startOfDay() DateTime

Available on DateTime, provided by the StartOfUnit extension

Returns start of the day
startOfHour() Moment

Available on Moment, provided by the StartOfUnitMoment extension

Returns start of the hour
startOfHour() DateTime

Available on DateTime, provided by the StartOfUnit extension

Returns start of the hour
startOfLocalWeek([int? weekStart]) Moment

Available on Moment, provided by the StartOfUnitMoment extension

Returns start of the week based on localization.weekStart. You can override this with weekStart
startOfLocalWeek([int? weekStart]) DateTime

Available on DateTime, provided by the StartOfUnit extension

Returns start of the week based on weekStart. If it's null, it uses Moment.defaultLocalization.weekStart
startOfMillisecond() Moment

Available on Moment, provided by the StartOfUnitMoment extension

Returns start of the millisecond
startOfMillisecond() DateTime

Available on DateTime, provided by the StartOfUnit extension

Returns start of the millisecond
startOfMinute() Moment

Available on Moment, provided by the StartOfUnitMoment extension

Returns start of the minute
startOfMinute() DateTime

Available on DateTime, provided by the StartOfUnit extension

Returns start of the minute
startOfMonth() Moment

Available on Moment, provided by the StartOfUnitMoment extension

Returns start of the month
startOfMonth() DateTime

Available on DateTime, provided by the StartOfUnit extension

Returns start of the month
startOfSecond() Moment

Available on Moment, provided by the StartOfUnitMoment extension

Returns start of the second
startOfSecond() DateTime

Available on DateTime, provided by the StartOfUnit extension

Returns start of the second
startOfYear() Moment

Available on Moment, provided by the StartOfUnitMoment extension

Returns start of the year
startOfYear() DateTime

Available on DateTime, provided by the StartOfUnit extension

Returns start of the year
subtract(Duration duration) Moment
Returns new Moment with subtracted duration
override
timeZoneFormatted([bool seperateWithColon = true]) String

Available on DateTime, provided by the MomentBenefits extension

Returns timezone:
timeZoneFormatted([bool seperateWithColon = true]) String
toIso8601String() String
Returns an ISO-8601 full-precision extended format representation.
inherited
toLocal() Moment
Returns this DateTime value in the local time zone.
override
toMoment({MomentLocalization? localization}) Moment

Available on DateTime, provided by the MomentBenefits extension

toString() String
Returns "LLL" formatted string
override
toUtc() Moment
Returns this DateTime value in the UTC time zone.
override

Operators

operator +(Duration duration) Moment
Returns new Moment with added duration
operator +(Duration other) → dynamic

Available on DateTime, provided by the MomentBenefits extension

Equivalent to add(other)
operator -(Duration duration) Moment
Returns new Moment with subtracted duration
operator -(Duration other) → dynamic

Available on DateTime, provided by the MomentBenefits extension

Equivalent to subtract(other)
operator <(DateTime other) → dynamic

Available on DateTime, provided by the MomentBenefits extension

Equivalent to isBefore(other)
operator <=(DateTime other) → dynamic

Available on DateTime, provided by the MomentBenefits extension

Equivalent to isBefore(other) || isAtSameMomentAs(other)
operator ==(Object other) bool
Whether other is a DateTime at the same moment and in the same time zone (UTC or local).
inherited
operator >(DateTime other) → dynamic

Available on DateTime, provided by the MomentBenefits extension

Equivalent to isAfter(other)
operator >=(DateTime other) → dynamic

Available on DateTime, provided by the MomentBenefits extension

Equivalent to isAfter(other) || isAtSameMomentAs(other)

Static Properties

defaultLocalization MomentLocalization
Any instances without explicit localization set will use the global localization.
getter/setter pair
epoch DateTime
epoch, but in the local timezone
getter/setter pair
epochUtc DateTime
epoch in UTC
getter/setter pair

Static Methods

duration(Duration duration, {MomentLocalization? localization, bool round = true, bool omitZeros = true, bool includeWeeks = false, Abbreviation form = Abbreviation.none, String? delimiter, DurationFormat format = DurationFormat.auto, bool dropPrefixOrSuffix = false}) String
Returns precise duration for duration in localization
endOfNextMonth() DateTime
End of the next month in the local timezone
endOfNextYear() DateTime
End of the next year in the local timezone
endOfPrevMonth() DateTime
End of the previous month in the local timezone
endOfPrevYear() DateTime
End of the previous year in the local timezone
endOfThisMonth() DateTime
End of the current month in the local timezone
endOfThisYear() DateTime
End of the current year in the local timezone
endOfToday() DateTime
End of today in the local timezone
endOfTomorrow() DateTime
End of tomorrow in the local timezone
endOfYesterday() DateTime
End of yesterday in the local timezone
parse(String input, {MomentLocalization? localization}) Moment
Uses DateTime.parse
override
setGlobalLocalization(MomentLocalization localization) → dynamic
Any instances without explicit localization set will use the global localization.
startOfNextMonth() DateTime
Start of the next month in the local timezone
startOfNextYear() DateTime
Start of the next year in the local timezone
startOfPrevMonth() DateTime
Start of the previous month in the local timezone
startOfPrevYear() DateTime
Start of the previous year in the local timezone
startOfThisMonth() DateTime
Start of the current month in the local timezone
startOfThisYear() DateTime
Start of the current year in the local timezone
startOfToday() DateTime
Start of today in the local timezone
startOfTomorrow() DateTime
Start of tomorrow in the local timezone
startOfYesterday() DateTime
Start of yesterday in the local timezone
tryParse(String input, {MomentLocalization? localization}) Moment?
Uses DateTime.tryParse
override