The dates
module is not available with JavaScript Runtime System Version 2. Read Replacing the dates
Module for guidance.
Importing with JavaScript Runtime Version 1:
var dates = require('dates')
The following sections describe the available methods within this module. Each section includes a table that lists the parameters for that method, as well as the parameter's type and description.
Convert a duration (milliseconds) to a DurationPeriod (structure)
Kind: Static method of dates
Returns: DurationPeriod
- Object with properties
periodDays
periodHours
periodMinutes
periodSeconds
periodMilliseconds
Parameter | Type | Description |
---|---|---|
milliseconds | ZonedDateTime | Milliseconds since the beginning of the epoch |
Kind: Inner class of dates
Access: Public
Returns: ZonedDateTime
- Immutable object containing a representation of a
date-time with a timezone. Use instead of the built-in Date
object.
Parameter | Type | Default | Description |
---|---|---|---|
timeZoneIdOrGeoPoint | String | Object | |
[ millisecondsFromEpoch ] | Integer | now | The number of milliseconds since the start of the UNIX epoch, January 1 1970 at 00:00:00 UTC |
Kind: Instance method of ZonedDateTime
Returns: Integer
- Milliseconds from start of epoch
of the specified dateTime.
Access: Public
Kind: Instance method of ZonedDateTime
Returns: String
- Timezone ID of the specified timezone
Access: Public
Kind: Instance method of ZonedDateTime
Returns: Object
- DateTime object with date and time properties
Access: Public
Kind: Instance method of ZonedDateTime
Returns: Integer
- Named day of the week
Access: Public
Kind: Instance method of ZonedDateTime
Returns: Integer
- Year of the specified date
Access: Public
Kind: Instance method of ZonedDateTime
Returns: Integer
- Month of the specified date
Access: Public
Kind: Instance method of ZonedDateTime
Returns: Integer
- Day of the specified date
Access: Public
Kind: Instance method of ZonedDateTime
Returns: Integer
- Hour of the specified time
Access: Public
Kind: Instance method of ZonedDateTime
Returns: Integer
- Minute of the specified time
Access: Public
Kind: Instance method of ZonedDateTime
Returns: Integer
- Second of the specified time
Access: Public
Kind: Instance method of ZonedDateTime
Returns: Integer
- Millisecond of the specified time
Access: Public
Kind: Instance method of ZonedDateTime
Returns: Integer
- Timezone offset, in seconds, of the specified timezone
Access: Public
Kind: Instance method of ZonedDateTime
Returns: Boolean
- Returns true
if the specified timezone
uses daylight savings time at the specified date and time,
otherwise false
Access: Public
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object with specified year set
Access: Public
Parameter | Type |
---|---|
year | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object with specified month set
Access: Public
Parameter | Type |
---|---|
month | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object with specified day set
Access: Public
Parameter | Type |
---|---|
day | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object with specified hour set
Access: Public
Parameter | Type |
---|---|
hour | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object with specified minute set
Access: Public
Parameter | Type |
---|---|
minute | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object with specified second set
Access: Public
Parameter | Type |
---|---|
second | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object with specified millisecond set
Access: Public
Parameter | Type |
---|---|
millisecond | Integer |
Construct a new ZonedDateTime for the same instant in time, but translated to a different timezone
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object with specified time zone applied
Access: Public
Parameter | Type |
---|---|
timeZoneId | String |
Construct a new ZonedDateTime for the same local dateTime, but translated to a different timezone
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object with specified time zone applied
Access: Public
Parameter | Type |
---|---|
timeZoneId | String |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object incremented by years
Access: Public
Parameter | Type |
---|---|
years | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object incremented by months
Access: Public
Parameter | Type |
---|---|
months | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object incremented by days
Access: Public
Parameter | Type |
---|---|
days | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object incremented by hours
Access: Public
Parameter | Type |
---|---|
hours | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object incremented by minutes
Access: Public
Parameter | Type |
---|---|
minutes | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object incremented by seconds
Access: Public
Parameter | Type |
---|---|
seconds | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object incremented by milliseconds
Access: Public
Parameter | Type |
---|---|
milliseconds | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object incremented by the given duration
Access: Public
Parameter | Type |
---|---|
duration | Object |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object decremented by years
Access: Public
Parameter | Type |
---|---|
years | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object decremented by months
Access: Public
Parameter | Type |
---|---|
months | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object decremented by days
Access: Public
Parameter | Type |
---|---|
days | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object decremented by hours
Access: Public
Parameter | Type |
---|---|
hours | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object decremented by minutes
Access: Public
Parameter | Type |
---|---|
minutes | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object decremented by seconds
Access: Public
Parameter | Type |
---|---|
seconds | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object decremented by milliseconds
Access: Public
Parameter | Type |
---|---|
milliseconds | Integer |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object decremented by the given duration
Access: Public
Parameter | Type |
---|---|
duration | Object |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object with time adjusted to
the start of the current day
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object with time adjusted to
the end of the current day
Compares one ZonedDateTime
to another. Comparison is based
solely off of the instant in time, regardless of timezone.
Kind: Instance method of ZonedDateTime
Returns: Integer
- 0 when other
is identical, -1 when other
is later, 1 when other
is earlier.
Parameter | Type | Description |
---|---|---|
other | ZonedDateTime | The ZonedDateTime to compare |
Compares one ZonedDateTime
to another. Comparison is based
solely off of the instant in time, regardless of timezone.
Kind: Instance method of ZonedDateTime
Returns: Boolean
- Returns true
when other
is identical, false
otherwise.
Parameter | Type | Description |
---|---|---|
other | ZonedDateTime | The ZonedDateTime to compare |
Compares one ZonedDateTime
to another. Comparison is based
solely off of the instant in time, regardless of timezone.
Kind: Instance method of ZonedDateTime
Returns: Boolean
- Returns true
when other
is later, false
otherwise
Parameter | Type | Description |
---|---|---|
other | ZonedDateTime | The ZonedDateTime to compare. |
Compares one ZonedDateTime to another. Comparison is based solely off of the instant in time, regardless of timezone.
Kind: Instance method of ZonedDateTime
Returns: Boolean
- Returns true
when other
is later or identical, false
otherwise.
Parameter | Type | Description |
---|---|---|
other | ZonedDateTime | The ZonedDateTime to compare. |
Compares one ZonedDateTime
to another. Comparison is based
solely off of the instant in time, regardless of timezone.
Kind: Instance method of ZonedDateTime
Returns: Boolean
- Returns true
when other
is earlier,
false
otherwise
Parameter | Type | Description |
---|---|---|
other | ZonedDateTime | The ZonedDateTime to compare |
Compares one ZonedDateTime
to another. Comparison is based
solely off of the instant in time, regardless of timezone.
Kind: Instance method of ZonedDateTime
Returns: Boolean
- Returns true
when other
is earlier or identical, false
otherwise.
Parameter | Type | Description |
---|---|---|
other | ZonedDateTime | The ZonedDateTime to compare |
Get the duration from this ZonedDateTime to another
Kind: Instance method of ZonedDateTime
Returns: DurationPeriod
- Object with property for unit (if provided), or properties
periodYears
periodMonths
periodDays
periodHours
periodMinutes
periodSeconds
periodMilliseconds
Parameter | Type | Description |
---|---|---|
other | ZonedDateTime | The ZonedDateTime to compare |
unit | String | The unit to use (can be Years, Months, Days, Hours Minutes, Seconds, Millis) |
Kind: Instance method of ZonedDateTime
Returns: ZonedDateTime
- New object with the same timezone and
instant in time
Kind: Instance method of ZonedDateTime
Returns: String
- The specified instant in time and timezone,
formatted as an ISO 8601
combined date and time
Kind: Instance method of ZonedDateTime
Returns: String
- The specified instant in time and timezone,
formatted using the default pattern,
Java's DateTimeFormatter.ISO_ZONED_DATE_TIME.
Kind: Instance method of ZonedDateTime
Returns: Object
- The specified instant in time and timezone,
returned as a JSON object.
{
"date": {
"year": integer,
"month": integer,
"day": integer
},
"time": {
"hour": integer,
"minute": integer,
"second": integer,
"millisecond": integer
}
}
Kind: Instance method of ZonedDateTime
Returns: String
- The specified instant in time and timezone,
formatted using the provided pattern.
If the pattern is null
, will use
Java's DateTimeFormatter.ISO_ZONED_DATE_TIME. An optional second argument can be provided to specify a locale; this is equivalent to Java's DateTimeFormatter.ofPattern(pattern, locale).
Parameter | Type | Description |
---|---|---|
[ pattern ] | String | A pattern as specified by Java's DateTimeFormatter |
[ locale ] | String | A locale in language-country format (ko-KR , en-US , etc.) |
Returns a new dates.ZonedDateTime
set to the default user time and timezone, or optionally, the specified timezone.
Kind: Static method of ZonedDateTime
Returns: ZonedDateTime
- A new object using all available date-time params.
Parameter | Type | Description |
---|---|---|
[ timezone ] | String | A timezone ID. If null, uses default timezone. |
Returns a new dates.ZonedDateTime
with the arguments provided.
All arguments are optional. If the first argument is a string,
it's assumed to be the timeZoneId
. Otherwise, the default user time zone
is used and all other inputs must be integer values
(month and day are 1-based, others are 0-based). If no arguments
are provided, then it's equivalent to calling dates.ZonedDateTime.now()
.
Kind: Static method of ZonedDateTime
Returns: ZonedDateTime
- A new object using all available date-time params.
Parameter | Type | Default | Description |
---|---|---|---|
[ timezone ] | String | A timezone ID. If null, uses default timezone. | |
[ year ] | Integer | 0 | |
[ month ] | Integer | 1 | |
[ day ] | Integer | 1 | |
[ hour ] | Integer | 0 | |
[ minute ] | Integer | 0 | |
[ second ] | Integer | 0 | |
[ millisecond ] | Integer | 0 |
Kind: Static method of ZonedDateTime
Returns: ZonedDateTime
- A new object at the start of the specified date, in the default timezone
Parameter | Type | Description |
---|---|---|
date | Date | An object with properties for year, month, and day |
Kind: Static method of ZonedDateTime
Returns: ZonedDateTime
- A new object at the start of the specified date and time, in the default timezone
Parameter | Type | Description |
---|---|---|
dateTime | DateTime | An object with properties for date and time |
Kind: Static method of ZonedDateTime
Returns: ZonedDateTime
- A new object at the beginning of the specified date, either in the specified timezone or in the default timezone.
An optional third argument can be provided to specify a locale; this is equivalent to Java's DateTimeFormatter.ofPattern(pattern, locale).
Parameter | Type | Description |
---|---|---|
input | String | The string to parse |
[ pattern ] | String | A pattern as specified by Java's DateTimeFormatter |
[ timeZoneId ] | String | The timezone ID |
[ locale ] | String | A locale in language-country format (ko-KR , en-US , etc.) |
Kind: Static method of ZonedDateTime
Returns: ZonedDateTime
- A new object at the specified time
of the current date, either in the specified timezone or in the default timezone.
An optional third argument can be provided to specify a locale; this is equivalent to Java's DateTimeFormatter.ofPattern(pattern, locale).
Parameter | Type | Description |
---|---|---|
input | String | The string to parse. |
[ pattern ] | String | A pattern as specified by Java's DateTimeFormatter |
[ timeZoneId ] | String | The timezone ID. |
[ locale ] | String | A locale in language-country format (ko-KR , en-US , etc.) |
Kind: Static method of ZonedDateTime
Returns: ZonedDateTime
- A new object at the specified date and time, either in the specified timezone or in the default timezone.
An optional third argument can be provided to specify a locale; this is equivalent to Java's DateTimeFormatter.ofPattern(pattern, locale).
Parameter | Type | Description |
---|---|---|
input | String | The string to parse |
[ pattern ] | String | A pattern as specified by Java's DateTimeFormatter |
[ timeZoneId ] | String | The timezone ID |
[ locale ] | String | A locale in language-country format (ko-KR , en-US , etc.) |
Kind: Inner method of dates
. Convenience method for creating a new dates.ZonedDateTime
for the current date-time. An optional timeZoneId
or geoPoint
can be provided, otherwise the default user time zone is used.
Returns: Object
- Current date-time for the specified timezone
or in the provided geo-point location.
Access: Public
Parameter | Type | Description |
---|---|---|
param | String | Object |