Date extension

on

Properties

clone DateTime
no setter
endOfDay DateTime
Return the end of a day for this date. The result will be in the local timezone.
no setter
endOfHour DateTime
Return the end of the hour for this date. The result will be in the local timezone.
no setter
endOfISOWeek DateTime
Return the end of ISO week for this date. The result will be in the local timezone.
no setter
endOfMinute DateTime
Return the end of the minute for this date. The result will be in the local timezone.
no setter
endOfMonth DateTime
Return the end of the month for this date. The result will be in the local timezone.
no setter
endOfSecond DateTime
Return the end of the second for this date. The result will be in the local timezone.
no setter
endOfWeek DateTime
Return the end of the week for this date. The result will be in the local timezone.
no setter
endOfYear DateTime
Return the end of the year for this date. The result will be in the local timezone.
no setter
getDate int
Get the day of the month of the given date. The day of the month 1..31.
no setter
getDay int
Get the day of the week of the given date.
no setter
getDayOfYear int
Days since year started. The result will be in the local timezone.
no setter
getDaysInMonth int
Days since month started. The result will be in the local timezone.
no setter
getDaysInYear int
Number of days in current year
no setter
getHours int
Get the hours of the given date. The hour of the day, expressed as in a 24-hour clock 0..23.
no setter
getISOWeek int
Get the ISO week index
no setter
getISOWeeksInYear int
Get the number of weeks in an ISO week-numbering year
no setter
getMicroseconds int
Get the microseconds of the given date. The microsecond 0...999.
no setter
getMicrosecondsSinceEpoch int
Get the microseconds since the 'Unix epoch' 1970-01-01T00:00:00Z (UTC).
no setter
getMilliseconds int
Get the milliseconds of the given date. The millisecond 0...999.
no setter
getMillisecondsSinceEpoch int
Get the milliseconds since the 'Unix epoch' 1970-01-01T00:00:00Z (UTC).
no setter
getMinutes int
Get the minutes of the given date. The minute 0...59.
no setter
getMonth int
Get the month of the given date. The month 1..12.
no setter
getSeconds int
Get the seconds of the given date. The second 0...59.
no setter
getTime int
get the numer of milliseconds since epoch
no setter
getTimeZoneName String
The time zone name. This value is provided by the operating system and may be an abbreviation or a full name. In the browser or on Unix-like systems commonly returns abbreviations, such as 'CET' or 'CEST'. On Windows returns the full name, for example 'Pacific Standard Time'.
no setter
getTimeZoneOffset Duration
The time zone offset, which is the difference between local time and UTC. The offset is positive for time zones east of UTC. Note, that JavaScript, Python and C return the difference between UTC and local time. Java, C# and Ruby return the difference between local time and UTC.
no setter
getWeek int
Get the week index
no setter
getWeekday int
The day of the week monday..sunday. In accordance with ISO 8601 a week starts with Monday, which has the value 1.
no setter
getWeekYear int
Get the local week-numbering year
no setter
getYear int
The year
no setter
isFirstDayOfMonth bool
Is the given date the first day of a month?
no setter
isFriday bool
Return true if this date day is friday
no setter
isFuture bool
Return true if this date isAfter Date.now
no setter
isLastDayOfMonth bool
Is the given date the last day of a month?
no setter
isLeapYear bool
Is the given date in the leap year?
no setter
isMonday bool
Return true if this date day is monday
no setter
isPast bool
Return true if this date isBefore Date.now
no setter
isSaturday bool
Return true if this date day is saturday
no setter
isSunday bool
Return true if this date day is sunday
no setter
isThisHour bool
Check if this date is in the same hour than DateTime.now
no setter
isThisMinute bool
Check if this date is in the same minute than DateTime.now
no setter
isThisMonth bool
Check if this date is in the same month than DateTime.now
no setter
isThisSecond bool
Check if this date is in the same second than DateTime.now
no setter
isThisYear bool
Check if this date is in the same year than DateTime.now
no setter
isThursday bool
Return true if this date day is thursday
no setter
isToday bool
Check if this date is in the same day than DateTime.today
no setter
isTomorrow bool
Check if this date is in the same day than DateTime.tomorrow
no setter
isTuesday bool
Return true if this date day is tuesday
no setter
isUTC bool
Return true if this DateTime is set as UTC.
no setter
isWednesday bool
Return true if this date day is wednesday
no setter
isWeekend bool
Return true if this DateTime is a saturday or a sunday
no setter
isYesterday bool
Check if this date is in the same day than DateTime.yesterday
no setter
local DateTime
Get Local DateTime from this DateTime
no setter
nextDay DateTime
The day after The day after this DateTime
no setter
nextMonth DateTime
The month after this DateTime
no setter
nextWeek DateTime
The week after this DateTime
no setter
nextYear DateTime
The year after this DateTime
no setter
previousDay DateTime
The day previous this DateTime
no setter
previousMonth DateTime
The month previous this DateTime
no setter
previousWeek DateTime
The week previous this DateTime
no setter
previousYear DateTime
The year previous this DateTime
no setter
secondsSinceEpoch int
Number of seconds since epoch time
no setter
startOfDay DateTime
Get a DateTime representing start of Day of this DateTime in local time.
no setter
startOfHour DateTime
Get a DateTime representing start of Hour of this DateTime in local time.
no setter
startOfISOWeek DateTime
Get a DateTime representing start of week (ISO week) of this DateTime in local time.
no setter
startOfISOWeekYear DateTime
Get the start of a local week-numbering year
no setter
startOfMinute DateTime
Get a DateTime representing start of minute of this DateTime in local time.
no setter
startOfMonth DateTime
Get a DateTime representing start of month of this DateTime in local time.
no setter
startOfSecond DateTime
Get a DateTime representing start of second of this DateTime in local time.
no setter
startOfWeek DateTime
Get a DateTime representing start of week of this DateTime in local time.
no setter
startOfWeekYear DateTime
Get the start of a local week-numbering year
no setter
startOfYear DateTime
Get a DateTime representing start of year of this DateTime in local time.
no setter
timestamp int
get the numer of milliseconds since epoch
no setter
toLocalTime DateTime
Get Date object in LocalTime of current object.
no setter
toUTC DateTime
Get Date object as UTC of current object.
no setter
utc DateTime
Get UTC DateTime from this DateTime
no setter

Methods

addDays(int amount, [bool ignoreDaylightSavings = false]) DateTime
Add a certain amount of days to this date
addHours(int amount, [bool ignoreDaylightSavings = false]) DateTime
Add a certain amount of hours to this date
addMicroseconds(int amount) DateTime
Add a certain amount of microseconds to this date
addMilliseconds(int amount) DateTime
Add a certain amount of milliseconds to this date
addMinutes(int amount, [bool ignoreDaylightSavings = false]) DateTime
Add a certain amount of minutes to this date
addMonths(int amount) DateTime
Add a certain amount of months to this date
addQuarters(int amount) DateTime
Add a certain amount of quarters to this date
addSeconds(int amount, [bool ignoreDaylightSavings = false]) DateTime
Add a certain amount of seconds to this date
addWeeks(int amount) DateTime
Add a certain amount of weeks to this date
addYears(int amount) DateTime
Add a certain amount of years to this date
closestIndexTo(Iterable<DateTime> datesArray) int?
Get index of the closest day to current one, returns null if empty Iterable is passed as argument
closestTo(Iterable<DateTime> datesArray) DateTime?
Get closest day to current one, returns null if empty Iterable is passed as argument
compare(DateTime other) int
Compares this Date object to other, returning zero if the values are equal. Returns a negative value if this Date isBefore other. It returns 0 if it isAtSameMomentAs other, and returns a positive value otherwise (when this isAfter other).
diff(DateTime other) Duration
Get the difference between this data and other date as a Duration
differenceInDays(DateTime other) int
Difference in days between this date and other
differenceInHours(DateTime other) int
Difference in hours between this date and other
differenceInMicroseconds(DateTime other) int
Difference in microseconds between this date and other
differenceInMilliseconds(DateTime other) int
Difference in milliseconds between this date and other
differenceInMinutes(DateTime other) int
Difference in minutes between this date and other
differenceInSeconds(DateTime other) int
Difference in seconds between this date and other
eachDay(DateTime date, {bool ignoreDaylightSavings = false}) Iterable<DateTime>
Return an Iterable of dates which is inclusive to this but exclusive to date
equals(DateTime other) bool
format(String pattern, [String locale = 'en_US']) String
Format this DateTime following the String pattern
isEqual(dynamic other) bool
Check if a date is equals to other
isSameDay(DateTime other) bool
Check if this date is in the same day than other
isSameHour(DateTime other) bool
Check if this date is in the same hour than other
isSameMinute(DateTime other) bool
Check if this date is in the same minute than other
isSameMonth(DateTime other) bool
Check if this date is in the same month than other
isSameOrAfter(DateTime other) bool
Return true if other isEqual or isAfter to this date
isSameOrBefore(DateTime other) bool
Return true if other isEqual or isBefore to this date
isSameSecond(DateTime other) bool
Check if this date is in the same second than other
isSameYear(DateTime other) bool
Check if this date is in the same year than other
isWithinInterval(Interval interval) bool
Checks if a DateTime is within an Interval
isWithinRange(DateTime startDate, DateTime endDate) bool
Checks if a DateTime is within a Rage (two dates that makes an Interval)
setDay(int day, [int? hour, int? minute, int? second, int? millisecond, int? microsecond]) DateTime
Change day of this date
setHour(int hour, [int? minute, int? second, int? millisecond, int? microsecond]) DateTime
Change hour of this date
setMicrosecond(int microsecond) DateTime
Change microsecond of this date
setMillisecond(int millisecond, [int? microsecond]) DateTime
Change millisecond of this date
setMinute(int minute, [int? second, int? millisecond, int? microsecond]) DateTime
Change minute of this date
setMonth(int month, [int? day, int? hour, int? minute, int? second, int? millisecond, int? microsecond]) DateTime
Change month of this date
setSecond(int second, [int? millisecond, int? microsecond]) DateTime
Change second of this date
setWeekDay(int weekday, [int weekStartsOn = DateTime.sunday]) DateTime
Change weekday of this date
setYear(int year, [int? month, int? day, int? hour, int? minute, int? second, int? millisecond, int? microsecond]) DateTime
Change year of this date
sub(Duration duration) DateTime
Subtracts a Duration from this DateTime
subDays(int amount) DateTime
Subtracts an amout of days from this DateTime
subHours(int amount) DateTime
Subtracts an amout of hours from this DateTime
subMicroseconds(dynamic amount) DateTime
Subtracts an amout of microseconds from this DateTime
subMilliseconds(dynamic amount) DateTime
Subtracts an amout of milliseconds from this DateTime
subMinutes(dynamic amount) DateTime
Subtracts an amout of minutes from this DateTime
subMonths(dynamic amount) DateTime
Subtracts an amout of months from this DateTime
subSeconds(dynamic amount) DateTime
Subtracts an amout of seconds from this DateTime
subtract(Duration duration) DateTime
Substract a Duration to this date
subYears(dynamic amount) DateTime
Subtracts an amout of years from this DateTime
timeago({String? locale, DateTime? clock, bool? allowFromNow}) String
Formats provided date to a fuzzy time like 'a moment ago' (use timeago package to change locales)
toHumanString() String

Operators

operator +(Duration other) DateTime
operator -(Duration other) DateTime
operator <(DateTime other) bool
operator <=(DateTime other) bool
operator >(DateTime other) bool
operator >=(DateTime other) bool

Static Properties

endOfToday DateTime
Return the end of today. The result will be in the local timezone.
no setter
endOfTomorrow DateTime
Return the end of tomorrow. The result will be in the local timezone.
no setter
endOfYesterday DateTime
Return the end of yesterday. The result will be in the local timezone.
no setter
startOfToday DateTime
Get a DateTime representing start of today of DateTime.today in local time.
no setter
today DateTime
Current date (Same as Date.now)
no setter
tomorrow DateTime
Tomorrow at same hour / minute / second than now
no setter
yesterday DateTime
Yesterday at same hour / minute / second than now
no setter

Static Methods

areRangesOverlapping(DateTime initialRangeStartDate, DateTime initialRangeEndDate, DateTime comparedRangeStartDate, DateTime comparedRangeEndDate) bool
Know if two ranges of dates overlaps
compareAsc(DateTime dateLeft, DateTime dateRight) int
Compare the two dates and return 1 if the first date isAfter the second, -1 if the first date isBefore the second or 0 first date isEqual the second.
compareDesc(DateTime dateLeft, DateTime dateRight) int
Compare the two dates and return -1 if the first date isAfter the second, 1 if the first date isBefore the second or 0 first date isEqual the second.
fromSecondsSinceEpoch(int secondsSinceEpoch, {bool isUtc = false}) DateTime
Number of seconds since epoch time / A.K.A Unix timestamp
isDate(dynamic argument) bool
Check if a Object if a DateTime, use for validation purposes
max(DateTime left, DateTime right) DateTime
Returns true if left isAfter than right
min(DateTime left, DateTime right) DateTime
Returns true if left isBefore than right
parse(String dateString, {String? pattern, String locale = 'en_US', bool isUTC = false}) DateTime
Transforms a date that follows a pattern from a String representation to a DateTime object
unix(int seconds) DateTime
Create a Date object from a Unix timestamp