DateTimeExtensions extension

Formatting, Jalali conversion, "time ago" and day math on DateTime. DateTime.now().toJalaliDate()

on

Properties

age → int

Available on DateTime, provided by the DateTimeExtensions extension

Full years from this birth date until today. birthDate.age
no setter
endOfDay → DateTime

Available on DateTime, provided by the DateTimeExtensions extension

The last moment of this day (23:59:59.999). date.endOfDay
no setter
isFuture → bool

Available on DateTime, provided by the DateTimeExtensions extension

True when this moment is still ahead.
no setter
isPast → bool

Available on DateTime, provided by the DateTimeExtensions extension

True when this moment has passed.
no setter
isToday → bool

Available on DateTime, provided by the DateTimeExtensions extension

True when this is today.
no setter
isTomorrow → bool

Available on DateTime, provided by the DateTimeExtensions extension

True when this is tomorrow.
no setter
isYesterday → bool

Available on DateTime, provided by the DateTimeExtensions extension

True when this was yesterday.
no setter
startOfDay → DateTime

Available on DateTime, provided by the DateTimeExtensions extension

Midnight at the start of this day. date.startOfDay
no setter
startOfMonth → DateTime

Available on DateTime, provided by the DateTimeExtensions extension

The first day of this Gregorian month at midnight.
no setter

Methods

addMonths(int months) → DateTime

Available on DateTime, provided by the DateTimeExtensions extension

Adds whole months, clamping the day (Jan 31 + 1 month → Feb 28/29). date.addMonths(1)
daysUntil(DateTime other) → int

Available on DateTime, provided by the DateTimeExtensions extension

Whole calendar days from this date to other (negative when other is earlier). today.daysUntil(birthday)
formatDate(String dateFormat) → String

Available on DateTime, provided by the DateTimeExtensions extension

Formats with an intl pattern. date.formatDate("yyyy-MM-dd HH:mm")
isSameDay(DateTime other) → bool

Available on DateTime, provided by the DateTimeExtensions extension

Same calendar day as other (time ignored). a.isSameDay(b)
toJalali() → UJalali

Available on DateTime, provided by the DateTimeExtensions extension

Converts to a UJalali date for Jalali math and formatting. date.toJalali().formatFullDate()
toJalaliDate() → String

Available on DateTime, provided by the DateTimeExtensions extension

Jalali date. "1403/01/01"
toJalaliDateTime() → String

Available on DateTime, provided by the DateTimeExtensions extension

Jalali date and time. "1403/01/01 14:05"
toJalaliDateTimeSeconds() → String

Available on DateTime, provided by the DateTimeExtensions extension

Jalali date and time with seconds. "1403/01/01 14:05:09"
toJalaliFormat(String pattern, {bool persianDigits = false}) → String

Available on DateTime, provided by the DateTimeExtensions extension

Jalali date with your own pattern (yyyy, mm, dd, mN month name, wN weekday…). date.toJalaliFormat("wN dd mN yyyy")
toTimeAgo({bool numericDates = false, bool persian = false}) → String

Available on DateTime, provided by the DateTimeExtensions extension

Short "time ago": "3h", "2d", "Just now" or "۳ ساعت پیش" with persian. createdAt.toTimeAgo(persian: true)
utcNow() → DateTime

Available on DateTime, provided by the DateTimeExtensions extension

The current UTC time (ignores this date). DateTime.now().utcNow()
utcNowIso() → String

Available on DateTime, provided by the DateTimeExtensions extension

The current UTC time as ISO text, ready for an API. "2024-03-20T10:00:00.000Z"