Incorrect timezone in Firefox compared to Safari using javascript Date ()

Following code

var date = new Date(); console.log( date ); 

gives me

 Sun Mar 06 2011 21:41:36 GMT+1300 (NZST) {} 

in firefox but

 Sun Mar 06 2011 21:40:51 GMT+1300 (NZDT) 

in Safari (this is correct).

My Date and Time system is installed in NZDT, so I wonder where Firefox came from NZST. Remember that in both cases, a UTC offset (+1300) is acceptable.

How can I get Firefox to display the correct time zone: NZDT?

+7
source share
3 answers

This was a bug fixed in Firefox v4 and later.

0
source

You should not rely on this output because it is different in other browsers (IE), you should use the getTimezoneOffset method instead.

 var date = new Date; console.log( date.getTimezoneOffset() ); 

The offset will change with daylight savings, but there are ways to work with it.

+1
source

If everything is as you need, except for "NZST", you can simply replace the plain text:

 console.log(date.toString().replace('NZST', 'NZDT')); 

Please note that this is a really simple fix for a display problem, it does not fix the root cause.

0
source

All Articles