Node.js错误地确定了夏令时 [英] Daylight Savings Time wrongly identified by Node.js

查看:93
本文介绍了Node.js错误地确定了夏令时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在时区,DST和Node.js方面遇到问题。它不能正确识别DST效果。我的操作系统是Windows 8.1,并已正确设置了时区值和DST。我尝试了这两种方法:

I'm having an issue with timezones, DST and Node.js. It doesn't identify correctly DST effects. My OS is Windows 8.1 and have the timezone value and DST well set. I tried these two methods:

1)节点的日期对象

我键入了节点提示中的以下代码并收到斜体字的答案:

I typed the following code in Node Prompt and received the answer in italic:

new Date()

2014年9月9日星期二18:42:36 GMT-0200(Horáriobrasileiro deverão(巴西夏令时))

但是,巴西DST将于10月19日开始,我们现在不在DST中。因此,小时将从现在开始偏移1小时。

However, the brazilian DST starts just in Oct 19th, we are not in DST right now. Therefore, the hour is shifted 1 hour from now.

2)节点时间

我从npm获得了节点时间包,以便能够更改时区。在代码中:

I got node-time package from npm, to be able to change Timezone. In the code:

time = require('time');
dateFormat = require('dateformat');

now = time.Date();
console.log(dateFormat(now.setTimezone('America/Sao_Paulo').getTime(), "yyyy-mm-dd HH:MM:ss Z"))

结果是

2014-09-09 18 :42:36 GMT-0200

巴西正常时区为GMT-0300。小时也是1小时的班次。

Brazilian normal timezone is GMT-0300. Hour is also 1 hour shifted.

我做错了吗?有解决方法吗?

推荐答案

节点时间包在Windows上不起作用。我什至无法安装它,所以我不确定你是怎么做到的。您应该卸载它。

The node-time package does not work on Windows. I couldn't even get it installed, so I'm not sure how you did. You should uninstall it.

如果需要在Node(或浏览器)中支持非本地时区,我建议 moment-timezone 的momentjs.com/ rel = nofollow noreferrer> moment.js >插件。

If you need support for non-local time zones in Node (or in the browser), I recommend moment.js with the moment-timezone plugin.

在设置了巴西时区的Windows上运行 new Date(),我得到正确的输出。

Running new Date() on Windows with the time zone set for Brazil, I get the correct output.

唯一的东西这将解释您的结果是:是否修改了时区注册表设置-但是您还会在任务栏上的系统时钟中看到错误的时间。因此,很抱歉,但是我无法复制其中的一部分。

The only thing that would explain your results is if the time zone registry settings were modified - but then you'd also see the wrong time in your system clock on your taskbar. So I'm sorry, but I cannot reproduce that part of it.

这篇关于Node.js错误地确定了夏令时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆