Date format must be declared using the combination of the predefined tokens and separators.
– Tokens:
Token | Description | Example
--|--|--
d
| day of the month without leading zero | 1, 2, ..., 31
dd
| day of the month with leading zero | 01, 02, ..., 31
D
| shortened day name of the week | Sum, Mon, ..., Sat
DD
| full day name of the week | Sunday, Monday, ..., Saturday
m
| numeric month without leading zero | 1, 2, ..., 12
mm
| numeric month with leading zero | 01, 02, ..., 12
M
| shortened month name | Jan, Feb, ..., Dec
MM
| full month name | January, February, ..., December
y
| year without leading zero | 1, 645, 1900, 2020
yy
| 2-digit year with leading zero | 01, 45, 00, 20
yyyy
| 4-digit year with leading zero | 0001, 0645, 1900, 2020
– Separators:
All printable ASCII characters other than numbers and alphabets, 年
, 月
and 日
Notes
yyyymmdd
) are not supported.yy
) is only supported by the built-in formatter; the built-in parser doesn't.You can write your custom parser/formatter to handle arbitrary format including the above. See
format
config option for the details.
dateDelimiter
config option.Date strings are expected to be formatted in the date format set in the format
config option (default: mm/dd/yyyy
), but it isn't necessary to match the format strictly.
The built-in parser uses the format string only to determine the sequence in which the date parts (year/month/day/day-of-the-week) and separators appear in the date string. The differences in separator characters, whether to have leading zeros and whether month name (full or short) or month number is used are ignored. Therefore, as long as the parts of a date string appear in the same order as the format's, the variations of the same date's date string are equally parsed to the same date.
There are some cases the parser treats the parts in specific way:
Date.prototype.setMonth()
Date.prototype.setDate()
Here are some examples of how irregular date strings are parsed.
yyyy-mm-dd
, 2020/04/22
⟹ April 22nd, 2020m.d.y
, 1/15 (2018)
⟹ January 15th, 2018d/m/y
, 05/06/07
⟹ June 5th, 0007yyyy-mm-dd
, 20-5-4
⟹ May 4th, 0020M-d-y
, 7-14-2020
⟹ July 14th, 2020M-d-y
,ap-22-2020
⟹ April 22nd, 2020sept-22-2020
⟹ September 22nd, 2020Ju-4-2020
⟹ June 4th, 2020July-4-2020
⟹ July 4th, 2020mm/dd/yyyy
,14/31/2019
⟹ March 2nd, 20200/0/2020
⟹ November 30th, 2019mm/yyyy
and current date is January 15th, 2020,04/2022
⟹ April 15th, 2022m/d/y
and current date is January 15th, 2020,4/22
⟹ April 22nd, 2020/22/2016
⟹ January 22nd, 20167/xx/2016
⟹ July 15th, 2016D m/d y
and current date is January 15th, 2020,xx 5/4 2022
⟹ May 4th, 20225/4 2022
⟹ October 13th, 2025 (= April 2022nd, 2020)You can use 'today'
as a shortcut to the current date.
You can combine multiple dates into a single date string by joining the dates with the delimiter set in the dateDelimiter config option.