This works in Chrome but not in Firefox.
new Date("2013-06-03 17:09:06-0400")
- Works fine in Chrome
- Gives 'NaN' in Firefox.
I would appreciate any help.
This works in Chrome but not in Firefox.
new Date("2013-06-03 17:09:06-0400")
I would appreciate any help.
Take a look at Mozilla Developer Network's Date and Date.parse documentation.
Specifically, it states:
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.
If you throw a 'T' in between the date and the time you get:
new Date("2013-06-03T17:09:06-0400")
=> Mon Jun 03 2013 14:09:06 GMT-0700 (PDT)
In both Chrome and Mozilla, although you have to account for the the current timezone (thus PDT) of the user's system.
In my experience, the only reliable way to construct a date object from a string in JavaScript is to parse the string yourself, and then use the version of the constructor that takes a separate numeric parameter for each field.
The string-based constructor is far too prone to issues with locale-related parsing errors.