Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript date constructor defaults to daylight savings even when current time is standard time

For Example:

var rd = new Date(2013, 2, 15, 10, 0, 0, 0);
rd.toString();

Will return "Fri Mar 15 2013 10:00:00 GMT-0700 (Pacific Daylight Time)" Even though the current active time on the platform is "Pacific Standard Time"..

This makes no sense - it should either return TZ as the current active TZ

Why does the constructor do this?

like image 428
user2076733 Avatar asked Jan 17 '26 17:01

user2076733


1 Answers

I am going to say that this is because DST starts on March 10. So if I wanted to use JS to enter a meeting I plan to have at 10:00 am, I'm going to want that to be 10:00 AM PDT.

I tested a few scenarios, I set my TZ to Pacific, and ran your code, it tells me the same as you, 10:00 PDT, I switched the date to the 9th and it said 10:00 PST, I then told my clock to ignore DST and set it back to the 15th and it then told me 10:00 PST.

I would have to say that this is working exactly how I would expect it to work based on the time settings on my local machine.

P.S.: IE is much more responsive to changes to my local machines time settings, I had to close and re-open chrome to get it to recognize I changed my clock.

like image 194
invertedSpear Avatar answered Jan 20 '26 08:01

invertedSpear