1

I've come across what appears to be an odd result from Firefox. Using the following format:

2013/01/01 00:00:00-0000

For my date, I run into an issue when the timezone goes "positive". For example.

new Date('2013/01/01 05:00:00-0000')
Date { Tue Jan 01 2013 00:00:00 GMT-0500 (EST) }

But.

new Date('2013/01/01 05:00:00+0100')
Date { Invalid Date }

I would expect rather to get:

Date { Mon Dec 31 2012 23:00:00 GMT-0500 (EST) }

It appears the + is what causes the problems, which seems to be a pretty big issue if I can't use timezones east of GMT.

EDIT: added a http://jsfiddle.net/utm4f/

Run in Firefox and it will return an invalid date (I am running Firefox 20 on OS X 10.8.3)

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Jeremy B.
  • 9,168
  • 3
  • 45
  • 57
  • Which version of Firefox exactly are you using? And do you have confirmed that it does work for negative offsets (you've shown `0` only)? – Bergi May 13 '13 at 17:33
  • FF 20.0. Yes, I've tried by using the FF console. -0200, -0300, etc... all work, as soon as you try +0100 it fails. – Jeremy B. May 13 '13 at 17:35

2 Answers2

0

Well, I found the issue by throwing whatever I can at it. Apparently Firefox requires a space between the time and timezone.

new Date('2013/01/01 05:00:00 +0100')
new Date('2013/01/01 05:00:00 -0100')

The - timezones won't error without a space, but the + ones will.

Jeremy B.
  • 9,168
  • 3
  • 45
  • 57
0

You might want to use ISO8601 values instead, such as:

2013-12-31T01:23:45-07:00

Parsing of ISO dates will work on all newer browsers, but fail on some older ones, most notably IE8. There is an excellent description of the browser support for this here, as well as a shim for older browser support.

But if you really want to support all of the inconsistencies in different browsers, the best way (IMHO) is with moment.js.

var m = moment('2013-12-31T01:23:45-07:00');

Or even using your other format, with an explicit parsing string:

var m = moment('2013/01/01 00:00:00-0000', 'YYYY/MM/DD HH:mm:ssZZ');
Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575