I am running Windows 10 Professional and my timezone and region settings are set to Brisbane/Australia (UTC+ 10:00). Furthermore, I am running Node.js on my system for an application I am building.
I ran the following in Node.js:
var x = new Date();
console.log(x);
It returned the following:
2017-09-07T23:42:33.719Z
Notice the Z at the end of the datetime string? This represents Zulu time. (UTC + 0)
I presume that this is set by default in Node.js when no timezone is specified. How can I specify the timezone globally in Node.js so as to ensure that all date objects a returned correctly?
You can set the TZ env to a timezone string.
For example:
You can also set
process.env.TZ
at runtime:Note, regardless of the timezone,
new Date()
returns UTC2017-09-08T01:05:58.103Z
when called like this.