Welcome to your one-stop shop for cross-browser JavaScript Date parsing behavior. This is not for the faint of heart. If you have other date formats which you'd like to contribute to this table, please contact me.
For some context and rules of thumb, please head back to JavaScript and Dates, What a Mess!.
Chrome | Firefox | IE | This browser | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
dateString | Time Zone | Meaning | <10 | 12-18 | 1-3 | 4-9 | 10 | 6-8 | 9 | ||
2009/07/12 | Local | Midnight, July 12, 2009 | ok | ok | ok | ||||||
2009/7/12 | Local | Midnight, July 12, 2009 | ok | ok | ok | ||||||
2009/07/12 12:34 | Local | 12:34:00 PM July 12, 2009 | ok | ok | ok | ||||||
2009/07/12 12:34:56 | Local | 12:34:56 PM July 12, 2009 | ok | ok | ok | ||||||
These formats work across all browsers. Stick to them if
possible. Note that if you specify hours, you must also specify minutes. Specifying hours alone does not work in any browser. | |||||||||||
2009/07/12 12:34:56.789 | Local | 12:34:56.789 PM, July 12, 2009 | Err | ok | Err | Err | |||||
Don't try to specify milliseconds. Only recent versions of
Chrome will understand you.
| |||||||||||
07/02/2012 | Local | Midnight, July 2, 2012 | ok | ok | ok | ||||||
7/2/2012 | Local | Midnight, July 2, 2012 | ok | ok | ok | ||||||
7/2/2012 12:34 | Local | 12:34 PM, July 2, 2012 | ok | ok | ok | ||||||
Somewhat surprisingly, these formats are also unambiguous.
Date.parse favors US (MM/DD/YYYY) over non-US
(DD/MM/YYYY) forms. These formats may be ambiguous to humans, however, so you should prefer YYYY/MM/DD if possible. | |||||||||||
2009-7-12 | Local | Midnight, July 12, 2009 | ok | Err | Err | ||||||
2009-07-12 | UTC | Midnight, July 12, 2009 | ok | Err | ok | Err | ok | ||||
2009-07-12 12:34 | Local | 12:34:00 PM July 12, 2009 | ok | Err | Err | ||||||
2009-07-12 12:34:56 | Local | 12:34:56 PM July 12, 2009 | ok | Err | Err | ||||||
1-1-2012 | Local | Midnight, January 1, 2012 | ok | Err | ok | ||||||
Using hyphens (-) instead of slashes (/) works in WebKit
browsers, but not in IE or FF. Beware the UTC parse of
YYYY-MM-DD!
| |||||||||||
1-1-12 | Local | Midnight, January 1, * | 2012 | Err | 1912 | ||||||
1/1/12 | Local | Midnight, January 1, * | 2012 | 1912 | 1912 | ||||||
1-1-12 11:12 | Local | 11:12:00 AM January 1, * | 2012 | Err | 1912 | ||||||
1/1/12 11:12 | Local | 11:12:00 AM January 1, * | 2012 | 1912 | 1912 | ||||||
1-1-12 11:12:34.567 | Local | 11:12:34 AM January 1, * | Err | 2012 | Err | Err | |||||
1/1/12 11:12:34.567 | Local | 11:12:34 AM January 1, * | Err | 2012 | Err | Err | |||||
1/2 | Local | Midnight, January 2, * | 2001 | Err | Err | ||||||
1-2 | Local | Midnight, January 2, * | 2001 | Err | Err | ||||||
1/2/3 | Local | Midnight, January 2, * | 2003 | 1903 | 1903 | ||||||
1-2-3 | Local | Midnight, January 2, * | 2003 | Err | 1903 | ||||||
If you don't specify a four-digit year, you'll get different
centuries in different browsers.
| |||||||||||
2011-10-10T14:48:00+0200 | (explicit) | 14:48:00 October 10, 2011 | Err | ok | Err | ok | Err | ||||
2011-10-10T14:48:00 | UTC | 14:48:00 October 10, 2011 | Err | ok | Err | ok | Err | ok | |||
2000-01-02T12:34:56Z | UTC | 12:34:56 January 2, 2000 | Err | ok | Err | ok | Err | ok | |||
2000-01-02T12:34:56.789Z | UTC | 12:34:56.789 January 2, 2000 | Err | ok | Err | ok | Err | ok | |||
2000-01-02T12:34:56.789012Z | UTC | 12:34:56 January 2, 2000 | Err | ok | Err | ok | Err | ||||
The ISO 8601-style formats guarantee an interpretation of your date string, but they have spotty support in older browsers. |