How set default timezone in node js for windows

2019-07-15 15:01发布

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

1条回答
beautiful°
2楼-- · 2019-07-15 15:29

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.

查看更多
登录 后发表回答