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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With