Generic extension methods
Usage
DateTime(1900).isLeapYear; // false
DateTime(2023, DateTime.july, 14).week; //
Operators
// Moon landing happened before present time
DateTime(1969, DateTime.july, 20) < now; // true
DateTime.utc(1970) == DateTime.fromMillisecondsSinceEpoch(0, isUtc: true); // true
List of extensions
Getters
-
dateReturns new object with hours, minutes, ..., microseconds omitted
-
isLeapYear -
isPast -
isFuture -
hour12 -
isAm -
isPm -
quarter -
weekISO Week number
-
weekYearYear according to ISO Week
-
dayOfYearOrdinal day of the year
- January 1st => 1
- December 31st => 365 (or 366 if
isLeapYear)
Methods
-
differenceInDays() -
timeZoneFormatted() -
isPastAnchored(DateTime anchor) -
isFutureAnchored(DateTime anchor) -
clone()Returns object of same type as the original.
Moment().clone(); // A new Moment instance
DateTime().clone(); // A new DateTime instance -
toMoment({MomentLocalization? localization}) -
format(...)Format
DateTimeobjects without need of creatingMoment. (Not really recommended, no point in avoiding Moment)
Operators
Now you can use operators on DateTime (and Moment) objects
-
+(other)is equivalent to
add(other) -
-(other)is equivalent to
subtract(other) -
>(other)is equivalent to
isAfter(other) -
<(other)is equivalent to
isBefore(other) -
>=(other)is equivalent to
isAfter(other) || isAtSameMomentAs(other) -
<=(other)is equivalent to
isBefore(other) || isAtSameMomentAs(other)