Constructor. Creates current time in local timezone.
nothing
Constructor. Parses ISO timestamp string. Non-existing local times are normalized by rounding up to the next DST offset.
String in ISO 8601 format. Instead of ISO time zone, it may include a space and then and IANA time zone. e.g. "2007-04-05T12:30:40.500" (no time zone, naive date) e.g. "2007-04-05T12:30:40.500+01:00" (UTC offset without daylight saving time) or "2007-04-05T12:30:40.500Z" (UTC) or "2007-04-05T12:30:40.500 Europe/Amsterdam" (IANA time zone, with daylight saving time if applicable)
Optional
timeZone: null | TimeZoneif given, the date in the string is assumed to be in this time zone. Note that it is NOT CONVERTED to the time zone. Useful for strings without a time zone
timezonecomplete.Argument.S if the given string is invalid
timezonecomplete.Argument.TimeZone if the given time zone is invalid
Constructor. Parses string in given LDML format. NOTE: does not handle eras/quarters/weeks/weekdays. Non-existing local times are normalized by rounding up to the next DST offset.
Date+Time string.
The LDML format that the string is assumed to be in
Optional
timeZone: null | TimeZoneif given, the date in the string is assumed to be in this time zone. Note that it is NOT CONVERTED to the time zone. Useful for strings without a time zone
timezonecomplete.ParseError if the given dateTimeString is wrong or not according to the pattern
timezonecomplete.Argument.FormatString if the given format string is invalid
timezonecomplete.Argument.Timezone if the given time zone is invalid
Constructor. You provide a date, then you say whether to take the date.getYear()/getXxx methods or the date.getUTCYear()/date.getUTCXxx methods, and then you state which time zone that date is in. Non-existing local times are normalized by rounding up to the next DST offset. Note that the Date class has bugs and inconsistencies when constructing them with times around DST changes.
A date object.
Optional
timeZone: null | TimeZoneThe time zone that the given date is assumed to be in (may be undefined or null for unaware dates)
timezonecomplete.Argument.GetFuncs if the getFuncs argument is invalid
timezonecomplete.Argument.TimeZone if the time zone argument is invalid
Get a date from a TimeStruct
Optional
timeZone: null | TimeZonetimezonecomplete.Argument.TimeZone if the given time zone argument is invalid
Constructor. Note that unlike JavaScript dates we require fields to be in normal ranges. Use the add(duration) or sub(duration) for arithmetic.
The full year (e.g. 2014)
The month [1-12] (note this deviates from JavaScript Date)
The day of the month [1-31]
Optional
hour: numberThe hour of the day [0-24)
Optional
minute: numberThe minute of the hour [0-59]
Optional
second: numberThe second of the minute [0-59]
Optional
millisecond: numberThe millisecond of the second [0-999]
Optional
timeZone: null | TimeZoneThe time zone, or null/undefined (for unaware dates)
timezonecomplete.Argument.Year if year invalid
timezonecomplete.Argument.Month if month invalid
timezonecomplete.Argument.Day if day invalid
timezonecomplete.Argument.Hour if hour invalid
timezonecomplete.Argument.Minute if minute invalid
timezonecomplete.Argument.Second if second invalid
timezonecomplete.Argument.Milli if milliseconds invalid
Constructor
milliseconds since 1970-01-01T00:00:00.000
Optional
timeZone: null | TimeZonethe time zone that the timestamp is assumed to be in (usually UTC).
timezonecomplete.Argument.TimeZone if the given time zone is invalid
timezonecomplete.Argument.UnixMillis if the given unix timestamp is not finite
Allow not using instanceof
Static
timeActual time source in use. Setting this property allows to fake time in tests. DateTime.nowLocal() and DateTime.nowUtc() use this property for obtaining the current time.
Add a time duration relative to UTC. Returns a new DateTime
this + duration
timezonecomplete.NotFound.Zone if the UTC time zone doesn't exist in the time zone database
Add an amount of time relative to UTC, as regularly as possible. Returns a new DateTime
Adding e.g. 1 hour will increment the utcHour() field, adding 1 month increments the utcMonth() field. Adding an amount of units leaves lower units intact. E.g. adding a month will leave the day() field untouched if possible.
Note adding Months or Years will clamp the date to the end-of-month if the start date was at the end of a month, i.e. contrary to JavaScript Date#setUTCMonth() it will not overflow into the next month
In case of DST changes, the utc time fields are still untouched but local time fields may shift.
Argument.Amount if amount is not a finite number or if you're trying to add a non-integer amount of years or months
Argument.Unit for invalid time unit
timezonecomplete.NotFound.Zone if the UTC time zone doesn't exist in the time zone database
Add an amount of time to the zone time, as regularly as possible. Returns a new DateTime
Adding e.g. 1 hour will increment the hour() field of the zone date by one. In case of DST changes, the time fields may additionally increase by the DST offset, if a non-existing local time would be reached otherwise.
Adding a unit of time will leave lower-unit fields intact, unless the result would be a non-existing time. Then an extra DST offset is added.
Note adding Months or Years will clamp the date to the end-of-month if the start date was at the end of a month, i.e. contrary to JavaScript Date#setUTCMonth() it will not overflow into the next month
nothing
Add an amount of time to the zone time, as regularly as possible. Returns a new DateTime
Adding e.g. 1 hour will increment the hour() field of the zone date by one. In case of DST changes, the time fields may additionally increase by the DST offset, if a non-existing local time would be reached otherwise.
Adding a unit of time will leave lower-unit fields intact, unless the result would be a non-existing time. Then an extra DST offset is added.
Note adding Months or Years will clamp the date to the end-of-month if the start date was at the end of a month, i.e. contrary to JavaScript Date#setUTCMonth() it will not overflow into the next month
Argument.Amount if amount is not a finite number or if you're trying to add a non-integer amount of years or months
Argument.Unit for invalid time unit
True iff this and other represent the same moment in time in UTC
nothing
Return a string representation of the DateTime according to the specified format. See LDML.md for supported formats.
The format specification (e.g. "dd/MM/yyyy HH:mm:ss")
Optional
locale: PartialLocaleOptional, non-english format month names etc.
The string representation of this DateTime
timezonecomplete.Argument.FormatString for invalid format pattern
True iff this >= other
nothing
True iff this > other
nothing
True iff this and other represent the same time and the same zone
nothing
True iff (this <= other)
nothing
True iff (this < other)
nothing
Same as add(-1*duration); Returns a new DateTime
timezonecomplete.NotFound.Zone if the UTC time zone doesn't exist in the time zone database
Same as add(-1*amount, unit); Returns a new DateTime
Argument.Amount if amount is not a finite number or if you're trying to add a non-integer amount of years or months
Argument.Unit for invalid time unit
timezonecomplete.NotFound.Zone if the UTC time zone doesn't exist in the time zone database
Same as addLocal(-1*amount, unit); Returns a new DateTime
nothing
Same as addLocal(-1*amount, unit); Returns a new DateTime
Argument.Amount if amount is not a finite number or if you're trying to add a non-integer amount of years or months
Argument.Unit for invalid time unit
Create an Excel timestamp for this datetime converted to the given zone. Does not work for dates < 1900
Optional
timeZone: null | TimeZoneOptional. Zone to convert to, default the zone the datetime is already in.
an Excel date/time number i.e. days since 1-1-1900 where 1900 is incorrectly seen as leap year
timezonecomplete.UnawareToAwareConversion if you try to convert a naive datetime to an aware one.
Convert to UTC and then return ISO string ending in 'Z'. This is equivalent to Date#toISOString() e.g. "2014-01-01T23:15:33 Europe/Amsterdam" becomes "2014-01-01T22:15:33Z". Unaware dates are assumed to be in UTC
timezonecomplete.NotFound.Zone if the UTC time zone doesn't exist in the time zone database
Returns this date converted to the given time zone. Unaware dates can only be converted to unaware dates (clone) Converting an unaware date to an aware date throws an exception. Use the constructor if you really need to do that.
Optional
zone: null | TimeZoneThe new time zone. This may be null or undefined to create unaware date.
The converted date
timezonecomplete.UnawareToAwareConversion if you try to convert a naive datetime to an aware one.
The ISO 8601 UTC week number. Week 1 is the week that has January 4th in it, and it starts on Monday. See https://en.wikipedia.org/wiki/ISO_week_date
Week number [1-53]
nothing
The ISO 8601 week number. Week 1 is the week that has January 4th in it, and it starts on Monday. See https://en.wikipedia.org/wiki/ISO_week_date
Week number [1-53]
nothing
Returns a new DateTime which is the date+time reinterpreted as in the new zone. So e.g. 08:00 America/Chicago can be set to 08:00 Europe/Brussels. No conversion is done, the value is just assumed to be in a different zone. Works for naive and aware dates. The new zone may be null.
Optional
zone: null | TimeZoneThe new time zone
A new DateTime with the original timestamp and the new zone.
nothing
Static
existsCheck whether a given date exists in the given time zone. E.g. 2015-02-29 returns false (not a leap year) and 2015-03-29T02:30:00 returns false (daylight saving time missing hour) and 2015-04-31 returns false (April has 30 days). By default, pre-1970 dates also return false since the time zone database does not contain accurate info before that. You can change that with the allowPre1970 flag.
Optional
zone: null | TimeZone(optional, default false): return true for pre-1970 dates
nothing
Static
fromCreate a DateTime from a Lotus 123 / Microsoft Excel date-time value i.e. a double representing days since 1-1-1900 where 1900 is incorrectly seen as leap year Does not work for dates < 1900
excel date/time number
Optional
timeZone: null | TimeZoneTime zone to assume that the excel value is in
a DateTime
timezonecomplete.Argument.N if n is not a finite number
timezonecomplete.Argument.TimeZone if the given time zone is invalid
Static
nowStatic
nowStatic
nowStatic
parseParse a date in a given format
the string to parse
the format the string is in. See LDML.md for supported formats.
Optional
zone: TimeZoneOptional, the zone to add (if no zone is given in the string)
Optional
locale: PartialLocaleOptional, different settings for constants like 'AM' etc
Optional
allowTrailing: booleanAllow trailing characters in the source string
timezonecomplete.ParseError if the given dateTimeString is wrong or not according to the pattern
timezonecomplete.Argument.FormatString if the given format string is invalid
DateTime class which is time zone-aware and which can be mocked for testing purposes.