Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS Date() returns correct timezone but wrong date

I am experiencing weird behaviour when trying to get current date using Date() in javascript. First, I set the timezone to Cuba by

sudo ln -sf /usr/share/zoneinfo/Cuba /etc/localtime

and ran Date() in another console running node.js. This was the output -

> Date()
'Thu Oct 31 2013 06:28:25 GMT+1100 (CDT)'

On changing the timezone,

sudo ln -sf /usr/share/zoneinfo/Asia/Vladivostok /etc/localtime

and running Date() again, this is the output -

> Date()
'Thu Oct 31 2013 06:28:31 GMT+1100 (VLAT)'

Can anyone please explain why does this happen and how can I get the time based on timezone ?

like image 306
Parin Porecha Avatar asked Oct 30 '13 19:10

Parin Porecha


1 Answers

Some messing around with OS timezones and node reveals that, while node correctly picks up timezone changes while it is running, it fails to update the offset. This is why both of the dates show GMT+1100.

If you restart node, you'll find that both the offset and the timezone are correct. I suspect that this is intentional to avoid the time changing unexpectedly during a run, but can't find anything to that effect with a Google search.

like image 160
Aaron Dufour Avatar answered Oct 18 '22 04:10

Aaron Dufour