The Date.parse()
static method parses a string representation of a date, and returns the date's timestamp.
Only the date time string format is explicitly specified to be supported. Other formats are implementation-defined and may not work across all browsers. A library can help if many different formats are to be accommodated.
Return value
A number representing the timestamp of the given date. If dateString
fails to be parsed as a valid date, NaN
is returned.
Description
This function is useful for setting date values based on string values, for example in conjunction with the setTime()
method.
Because parse()
is a static method of Date
, you always use it as Date.parse()
, rather than as a method of a Date
object you created.
Using Date.parse()
The following calls all return 1546300800000
. The first will imply UTC time because it's date-only, and the others explicitly specify the UTC timezone.
Date.parse("2019-01-01");
Date.parse("2019-01-01T00:00:00.000Z");
Date.parse("2019-01-01T00:00:00.000+00:00");
The following call, which does not specify a time zone will be set to 2019-01-01 at 00:00:00 in the local timezone of the system, because it has both date and time.
Date.parse("2019-01-01T00:00:00");
Non-standard date strings
Note: This section contains implementation-specific behavior that can be inconsistent across implementations.
Implementations usually default to the local time zone when the date string is non-standard. For consistency, we will assume that the code uses the UTC timezone.
Date.parse("Jan 1, 1970");
Date.parse("Thu, 01 Jan 1970 00:00:00");
Date.parse("1970,1,1");
Date.parse("02 01 1970");
Date.parse("Thu, 01 Jan 1970 00:00:00 GMT+0300");
Date.parse("0");
Date.parse("28");
Date.parse("70/01/01");
Date.parse("2014-25-23");
Date.parse("Mar 32, 2014");
Date.parse("2014/25/23");
Date.parse("2014-02-30");
Date.parse("02/30/2014");
Specifications
Browser compatibility
|
Desktop |
Mobile |
Server |
|
Chrome |
Edge |
Firefox |
Opera |
Safari |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
WebView Android |
Deno |
Node.js |
parse |
1 |
12 |
1 |
3 |
1 |
18 |
4 |
10.1 |
1 |
1.0 |
4.4 |
1.0 |
0.10.0 |
iso_8601 |
6 |
12 |
4 |
6 |
5.1 |
18 |
4 |
10.1 |
5 |
1.0 |
≤37 |
1.0 |
0.12.0 |