Javascript返回错误的日期值(NodeJS) [英] Javascript returns wrong Date values (NodeJS)
问题描述
我正在处理NodeJS项目,但日期值错误。而且我不明白我在做什么错。
I'm working on a NodeJS Projects and I get wrong Date values. And I don't get what I am doing wrong.
var d = new Date(results[1].timestamp);
console.log(results[1].timestamp); // 2016-05-10T13:29:47 <- this is right (stored at my DataBase)
console.log(d.getDate()); //10
console.log(d.getFullYear()); //2016
console.log(d.getMonth()); //4
console.log(d.getDay()); //2
console.log(d.getHours()); //15
console.log(d.getMinutes()); //29
console.log(d.getSeconds()); //47
因此,月,日和小时是错误的。
我在Mac上的Google chrome中看到了这些结果
So Month, Day and Hours are wrong. I see these results in google chrome at my Mac
感谢您的帮助
推荐答案
此处有一些错误:
-
getMonth
返回基于0
的月份。那就是五月是04
。
getMonth
returns a0
based month. That is May is04
.
getDay
返回星期几。我想你想 getDate
getDay
returns the day of the week. I guess you want getDate
日期被解析为UTC和 getHour
是根据区域设置的。因此,小时可能与您想要的时间有所不同(但在这里它似乎是精确的,因为它与输入的值相同)。
the date is parsed as UTC and getHour
is according to the locale. So the hour might be different from what you want (but right here it seems to be "exact", as is it's the same value than inputted).
下一个问题的提示:请看一些文档。例如 MDN 。
A tip for your next problems: Have a look at some documentation. For example the MDN.
这篇关于Javascript返回错误的日期值(NodeJS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!