本文介绍了如何在node.js中设置默认时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在node.js中设置默认时区?
How do I set the default timezone in node.js?
推荐答案
根据此Google组线程,您可以在调用任何日期函数之前设置TZ环境变量.刚刚对其进行了测试,就可以了.
According to this google group thread, you can set the TZ environment variable before calling any date functions. Just tested it and it works.
> process.env.TZ = 'Europe/Amsterdam'
'Europe/Amsterdam'
> d = new Date()
Sat, 24 Mar 2012 05:50:39 GMT
> d.toLocaleTimeString()
'06:50:39'
> ""+d
'Sat Mar 24 2012 06:50:39 GMT+0100 (CET)'
但是您以后不能更改时区,因为到那时Node已经读取了环境变量.
You can't change the timezone later though, since by then Node has already read the environment variable.
这篇关于如何在node.js中设置默认时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!