Date.parse

Did you know that you can read content offline by using one of these tools? If you would like to read offline MDN content in another format, let us know by commenting on Bug 665750.

Dash App

Summary

Parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.

Method of Date
Implemented in JavaScript 1.0
ECMAScript Edition ECMAScript 1st Edition

Syntax

Date.parse(dateString)

Parameters

dateString
A string representing an RFC2822 or ISO 8601 date.

Description

The parse method takes a date string (such as "Dec 25, 1995") and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. The local time zone is used to interpret arguments that do not contain time zone information. This function is useful for setting date values based on string values, for example in conjunction with the setTime method and the Date object.

Given a string representing a time, parse returns the time value. It accepts the RFC2822 / IETF date syntax (RFC2822 Section 3.3), e.g. "Mon, 25 Dec 1995 13:30:00 GMT". It understands the continental US time-zone abbreviations, but for general use, use a time-zone offset, for example, "Mon, 25 Dec 1995 13:30:00 +0430" (4 hours, 30 minutes east of the Greenwich meridian). If you do not specify a time zone, the local time zone is assumed. GMT and UTC are considered equivalent.

JavaScript 1.8.5 note

A subset of ISO 8601 formatted date strings can now also be parsed.

Alternatively, the date/time string may be in ISO 8601 format. Starting with JavaScript 1.8.5 (Firefox 4), a subset of ISO 8601 is supported. For example, "2011-10-10" (just date) or "2011-10-10T14:48:00" (date and time) can be passed and parsed.

Note that while time zone specifiers are used during date string parsing to properly interpret the argument, they do not affect the value returned, which is always the number of milliseconds between January 1, 1970 00:00:00 UTC and the point in time represented by the argument.

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.

Examples

Example: Using parse

If IPOdate is an existing Date object, then you can set it to August 9, 1995 (local time) as follows:

IPOdate.setTime(Date.parse("Aug 9, 1995"));

Some other examples:

// Returns 807937200000 in time zone GMT-0300, and other values in other
// timezones, since the argument does not specify a time zone.
Date.parse("Aug 9, 1995");
// Returns 807926400000 no matter the local time zone.
Date.parse("Wed, 09 Aug 1995 00:00:00 GMT");
// Returns 807937200000 in timezone GMT-0300, and other values in other
// timezones, since there is no time zone specifier in the argument.
Date.parse("Wed, 09 Aug 1995 00:00:00");
// Returns 0 no matter the local time zone.
Date.parse("Thu, 01 Jan 1970 00:00:00 GMT");
// Returns 14400000 in timezone GMT-0400, and other values in other 
// timezones, since there is no time zone specifier in the argument.
Date.parse("Thu, 01 Jan 1970 00:00:00");
// Returns 14400000 no matter the local time zone.
Date.parse("Thu, 01 Jan 1970 00:00:00 GMT-0400");

See also

Tags (2)