I'm trying to set the time zone at the start of the application
set "TZ=UTC"
node main.js
But is not work:
// main.js
var tz = process.env.TZ;
var date = new Date();
console.log(tz, '||', date);
UTC Tue Nov 17 2015 21:41:29 GMT+0300
To get the current browser's time zone, you can use the getTimezoneOffset() method from the JavaScript Date object. The getTimezoneOffset() returns the time difference, in minutes, between UTC time and local time.
Sometimes, we may want to initialize a JavaScript date to a particular time zone. The default time zone is UTC.
What time zone does the Javascript new Date() use? Date objects work with the number of milliseconds since The Epoch (Jan 1st 1970 at midnight GMT).
I published a small utility called set-tz which takes advantage of tzutil
CLI command. When you call setTZ()
it effectively changes your PC's timezone so beware-if you kill the process, you'll need to manually revert back after you're done-I am assuming you'r process is short-lived.
If you don't kill your process, it will revert your original timezone back for you.
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