mozilla
Your Search Results

    Date.parse Redirect 1

    Summary

    The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.

    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. 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. The local time zone is used to interpret arguments in RFC2822 Section 3.3 format that do not contain time zone information.

    ECMAScript 5 ISO-8601 format support

    Alternatively, the date/time string may be in ISO 8601 format. For example, "2011-10-10" (just date) or "2011-10-10T14:48:00" (date and time) can be passed and parsed. The UTC time-zone is used to interpret arguments in ISO 8601 format that do not contain time zone information.

    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.

    Differences in assumed time-zone

    The dateString of "March 7, 2014" returns a different date than "2014-03-07" unless the local time-zone is UTC. When converting a dateString of "March 7, 2014" the local time-zone is assumed. When converting a dateString of "2014-03-07" the UTC time-zone is assumed. This results in two different Date values depending on the format of the string that is being converted.

    Examples

    Example: Using Date.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");
    

    Specifications

    Specification Status Comment
    ECMAScript 1st Edition. Implemented in JavaScript 1.0 Standard Initial definition.
    ECMAScript Language Specification 5.1th Edition (ECMA-262) Standard ISO 8601 format added
    ECMAScript Language Specification 6th Edition (ECMA-262) Draft  

    Browser compatibility

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
    Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
    ISO 8601 format (Yes) 4.0 (2.0) 9 (Yes) (Yes)
    Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
    Basic support ? (Yes) (Yes) ? ? ?
    ISO 8601 format ? (Yes) (Yes) ? ? ?

    See also

    Document Tags and Contributors

    Contributors to this page: Sheppy
    Last updated by: Sheppy,
    Hide Sidebar