本文介绍了如何在 node js 中为 windows 设置默认时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在应用程序开始时设置时区
设置TZ=UTC"节点 main.js
但是不行:
//main.jsvar tz = process.env.TZ;var date = new Date();console.log(tz, '||', 日期);
UTC 时间 2015 年 11 月 17 日星期二 21:41:29 GMT+0300
解决方案
我发布了一个名为 的小实用程序set-tz 它利用了 tzutil
CLI 命令.当您调用 setTZ()
时,它会有效地更改您 PC 的时区,因此请注意 - 如果您终止该进程,则需要在完成后手动恢复 - 我假设您的进程是短暂的.如果您不终止进程,它会为您恢复原始时区.
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);
解决方案
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.
这篇关于如何在 node js 中为 windows 设置默认时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!