Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why new Date() function gives different output in chrome and firefox

I am passing this new Date into both Firefox and Chrome console (same computer, and time zone) and I am getting mixed results.So confusing... In chrome new Date(); //Wed Dec 09 2015 18:06:55 GMT+0530 (IST)

In firefox new Date(); //Date 2015-12-09T12:36:34.410Z

like image 887
Tanvi Shah Avatar asked Feb 09 '23 08:02

Tanvi Shah


1 Answers

Your confusion is caused by different time-zones displaying.

Your Chrome gives you the time in UTC+0, while Firefox gives you the time in GMT+0530.

You can specify you want both to always be UTC by writing

var myDate = new Date();
myDate.toISOString() // will give you a date in the format you see by Chrome
like image 60
AlexD Avatar answered Feb 10 '23 23:02

AlexD