Date
ฦฌ Date: Format
["YYYY-MM-DD"
] & string
An Iso.Date
represents a calendar date. "Calendar date" refers to the concept of a date as expressed in everyday usage, independent of any time zone. For example, it could be used to represent an event on a calendar which happens during the whole day no matter which time zone it's happening in.
Iso.Date
refers to the whole of a specific day; if you need to refer to a specific time on that day, use Iso.DateTime
. An Iso.Date
can be converted into a Iso.ZonedDateTime
by combining it with a Iso.Time
and Iso.TimeZone
using the toZonedDateTime()
function. It can also be combined with a Iso.Time
to yield a "zoneless" Iso.DateTime
using the toDateTime()
method.
Iso.YearMonth
and Iso.MonthDay
carry less information than Iso.Date
and should be used when complete information is not required.
Defined in
now
โธ now(timeZone?
): Date
This method gets the current calendar date according to the system settings. Optionally a time zone can be given in which the time is computed, instead of the current system time zone.
Parameters
Name | Type | Description |
---|---|---|
timeZone? | string | The time zone to get the current date and time in, as a string. If not given, the current system time zone will be used. |
Returns
an Iso.Date
string representing the date.
Defined in
fromNumbers
โธ fromNumbers(year
, month
, day
): Date
Parameters
Name | Type |
---|---|
year | number |
month | number |
day | number |
Returns
Defined in
isValid
โธ isValid(date
): date is Date
Parameters
Name | Type |
---|---|
date | unknown |
Returns
date is Date
Defined in
assertIsValid
โธ assertIsValid(date
): asserts date is Date
Parameters
Name | Type |
---|---|
date | unknown |
Returns
asserts date is Date
Defined in
getYear
โธ getYear(date
): number
Parameters
Name | Type |
---|---|
date | Date |
Returns
number
Defined in
getMonth
โธ getMonth(date
): number
Parameters
Name | Type |
---|---|
date | Date |
Returns
number
Defined in
getDay
โธ getDay(date
): number
Parameters
Name | Type |
---|---|
date | Date |
Returns
number
Defined in
getDayOfWeek
โธ getDayOfWeek(date
): number
Parameters
Name | Type |
---|---|
date | Date |
Returns
number
Defined in
getDayOfYear
โธ getDayOfYear(date
): number
Parameters
Name | Type |
---|---|
date | Date |
Returns
number
Defined in
getWeekOfYear
โธ getWeekOfYear(date
): number
Parameters
Name | Type |
---|---|
date | Date |
Returns
number
Defined in
getDaysInMonth
โธ getDaysInMonth(date
): number
Parameters
Name | Type |
---|---|
date | Date |
Returns
number
Defined in
getDaysInYear
โธ getDaysInYear(date
): number
Parameters
Name | Type |
---|---|
date | Date |
Returns
number
Defined in
inLeapYear
โธ inLeapYear(date
): boolean
Parameters
Name | Type |
---|---|
date | Date |
Returns
boolean
Defined in
with
โธ with(dateTime
, temporalDateLike
, options?
): Date
Parameters
Name | Type |
---|---|
dateTime | Date |
temporalDateLike | Object |
temporalDateLike.day? | number |
temporalDateLike.month? | number |
temporalDateLike.year? | number |
options? | Object |
options.overflow? | TemporalOverflow |
Returns
Defined in
add
โธ add(date
, temporalDurationLike
, options?
): Date
Parameters
Name | Type |
---|---|
date | Date |
temporalDurationLike | Duration | { years? : number ; months? : number ; weeks? : number ; days? : number ; hours? : number ; minutes? : number ; seconds? : number ; milliseconds? : number } |
options? | Object |
options.overflow? | TemporalOverflow |
Returns
Defined in
subtract
โธ subtract(date
, temporalDurationLike
, options?
): Date
Parameters
Name | Type |
---|---|
date | Date |
temporalDurationLike | Duration | { years? : number ; months? : number ; weeks? : number ; days? : number ; hours? : number ; minutes? : number ; seconds? : number ; milliseconds? : number } |
options? | Object |
options.overflow? | TemporalOverflow |
Returns
Defined in
until
โธ until(date
, other
, options?
): Duration
Parameters
Name | Type |
---|---|
date | Date |
other | Date |
options? | Object |
options.largestUnit? | TemporalSingularUnit | TemporalPluralUnit | "auto" |
options.smallestUnit? | TemporalSingularUnit | TemporalPluralUnit |
options.roundingIncrement? | number |
options.roundingMode? | TemporalRoundingMode |
Returns
Defined in
since
โธ since(date
, other
, options?
): Duration
Parameters
Name | Type |
---|---|
date | Date |
other | Date |
options? | Object |
options.largestUnit? | TemporalSingularUnit | TemporalPluralUnit | "auto" |
options.smallestUnit? | TemporalSingularUnit | TemporalPluralUnit |
options.roundingIncrement? | number |
options.roundingMode? | TemporalRoundingMode |
Returns
Defined in
equals
โธ equals(date
, other
): boolean
Parameters
Name | Type |
---|---|
date | Date |
other | Date |
Returns
boolean
Defined in
isEqual
โธ isEqual(date
, other
): boolean
alias for equals
Parameters
Name | Type |
---|---|
date | Date |
other | Date |
Returns
boolean
Defined in
isBefore
โธ isBefore(date
, other
): boolean
Parameters
Name | Type |
---|---|
date | Date |
other | Date |
Returns
boolean
Defined in
isAfter
โธ isAfter(date
, other
): boolean
Parameters
Name | Type |
---|---|
date | Date |
other | Date |
Returns
boolean
Defined in
isEqualOrBefore
โธ isEqualOrBefore(date
, other
): boolean
Parameters
Name | Type |
---|---|
date | Date |
other | Date |
Returns
boolean
Defined in
isEqualOrAfter
โธ isEqualOrAfter(date
, other
): boolean
Parameters
Name | Type |
---|---|
date | Date |
other | Date |
Returns
boolean
Defined in
toDateTime
โธ toDateTime(date
, time?
): DateTime
Parameters
Name | Type |
---|---|
date | Date |
time? | Time |
Returns
Defined in
toZonedDateTime
โธ toZonedDateTime(date
, item
): ZonedDateTime
Parameters
Name | Type |
---|---|
date | Date |
item | string | { timeZone : string ; time? : Time } |
Returns
Defined in
toYearMonth
โธ toYearMonth(date
): YearMonth
Parameters
Name | Type |
---|---|
date | Date |
Returns
Defined in
toMonthDay
โธ toMonthDay(date
): MonthDay
Parameters
Name | Type |
---|---|
date | Date |
Returns
Defined in
getFields
โธ getFields(date
): DateSlots
Parameters
Name | Type |
---|---|
date | Date |
Returns
DateSlots
Defined in
from
โธ from(item
, options?
): Date
Parameters
Name | Type |
---|---|
item | any |
options? | Object |
options.overflow | TemporalOverflow |
Returns
Defined in
compare
โธ compare(one
, two
): number
Parameters
Name | Type |
---|---|
one | Date |
two | Date |
Returns
number
Defined in
format
โธ format(date
, format
): string
summary
Format the ZonedDateTime.
description
Return the formatted ZonedDateTime string in the given format.
The characters wrapped between two single quotes characters (') are escaped. Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote. (see the last example)
Format of the string is based on Unicode Technical Standard #35: https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table with a few additions (see note 7 below the table).
Accepted patterns:
Unit | Pattern | Result examples | Notes |
---|---|---|---|
Era | G..GGG | AD, BC | |
GGGG | Anno Domini, Before Christ | 1 | |
GGGGG | A, B | ||
Calendar year | y | 44, 1, 1900, 2017 | 4 |
yo | 44th, 1st, 0th, 17th | 4,5 | |
yy | 44, 01, 00, 17 | 4 | |
yyy | 044, 001, 1900, 2017 | 4 | |
yyyy | 0044, 0001, 1900, 2017 | 4 | |
yyyyy | ... | 2,4 | |
Extended year | u | -43, 0, 1, 1900, 2017 | 4 |
uu | -43, 01, 1900, 2017 | 4 | |
uuu | -043, 001, 1900, 2017 | 4 | |
uuuu | -0043, 0001, 1900, 2017 | 4 | |
uuuuu | ... | 2,4 | |
Quarter | Q | 1, 2, 3, 4 | |
Qo | 1st, 2nd, 3rd, 4th | 5 | |
01, 02, 03, 04 | |||
QQQ | Q1, Q2, Q3, Q4 | ||
QQQQ | 1st quarter, 2nd quarter, ... | 1 | |
QQQQQ | 1, 2, 3, 4 | 3 | |
Month | M | 1, 2, ..., 12 | |
Mo | 1st, 2nd, ..., 12th | 5 | |
MM | 01, 02, ..., 12 | ||
MMM | Jan, Feb, ..., Dec | ||
MMMM | January, February, ..., December | 1 | |
MMMMM | J, F, ..., D | ||
ISO week of year | I | 1, 2, ..., 53 | 5 |
Io | 1st, 2nd, ..., 53th | 5 | |
II | 01, 02, ..., 53 | 5 | |
Day of month | d | 1, 2, ..., 31 | |
do | 1st, 2nd, ..., 31st | 5 | |
dd | 01, 02, ..., 31 | ||
ISO day of week | i | 1, 2, 3, ..., 7 | 5 |
io | 1st, 2nd, ..., 7th | 5 | |
ii | 01, 02, ..., 07 | 5 | |
iii | Mon, Tue, Wed, ..., Sun | 5 | |
iiii | Monday, Tuesday, ..., Sunday | 1,5 | |
iiiii | M, T, W, T, F, S, S | 5 | |
iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 5 | |
Long localized date | P | 04/29/1453 | 5 |
PP | Apr 29, 1453 | 5 | |
PPP | April 29th, 1453 | 5 | |
PPPP | Friday, April 29th, 1453 | 1,5 |
Notes:
Any sequence of the identical letters is a pattern, unless it is escaped by the single quote characters (see below). If the sequence is longer than listed in table (e.g.
EEEEEEEEEEE
) the output will be the same as default pattern for this unit, usually the longest one (in case of ISO weekdays,EEEE
). Default patterns for units are marked with "2" in the last column of the table.format("2017-11-06", 'MMM') //=> 'Nov'
format("2017-11-06", 'MMMM') //=> 'November'
format("2017-11-06", 'MMMMM') //=> 'N'
format("2017-11-06", 'MMMMMM') //=> 'November'
format("2017-11-06", 'MMMMMMM') //=> 'November'
Some patterns could be unlimited length (such as
yyyyyyyy
). The output will be padded with zeros to match the length of the pattern.format("2017-11-06", 'yyyyyyyy') //=> '00002017'
QQQQQ
could be not strictly numerical in some locales. These tokens represent the shortest form of the quarter.The main difference between
y
andu
patterns are B.C. years:Year y
u
AC 1 1 1 BC 1 1 0 BC 2 2 -1 Also
yy
always returns the last two digits of a year, whileuu
pads single digit years to 2 characters and returns other years unchanged:Year yy
uu
1 01 01 14 14 14 376 76 376 1453 53 1453 These patterns are not in the Unicode Technical Standard #35:
i
: ISO day of weekI
: ISO week of yearo
: ordinal number modifierP
: long localized datep
: long localized time
- Characters are escaped using single quote symbols (
'
).
example
// Represent 11 February 2014 in middle-endian format:
var result = format("2014-02-11", 'MM/dd/yyyy')
//=> '02/11/2014'
Parameters
Name | Type | Description |
---|---|---|
date | Date | the original date |
format | string | the string of tokens |
Returns
string
the formatted date string
Defined in
chain
โธ chain(date
): IDateChain
Parameters
Name | Type |
---|---|
date | Date |
Returns
IDateChain