admin管理员组文章数量:1356905
This is my code:
var feedDataTimestamp = new Date("2014-01-14T00:04:40+0000").getTime();
var parsedDate = new Date(+feedDataTimestamp);
alert(parsedDate.getHours());
but it should print 0, not 1: time is 00:04:40
This is my code:
var feedDataTimestamp = new Date("2014-01-14T00:04:40+0000").getTime();
var parsedDate = new Date(+feedDataTimestamp);
alert(parsedDate.getHours());
but it should print 0, not 1: time is 00:04:40
2 Answers
Reset to default 8Because you (according to your Stackoverflow profile) are in Italy, so your time zone is UTC+1.
The time stamp you are inputting is UTC+0.
parsedDate
will be in local time.
Use the getUTCHours()
method if you want to get UTC time instead of local time.
You set the timezone in the parsed string as +0000
so you seem to want the hours in UTC, use
alert(parsedDate.getUTCHours())
本文标签: javascriptWhy does DategetHours() return hour1Stack Overflow
版权声明:本文标题:javascript - Why does Date#getHours() return hour + 1? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744035137a2579631.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论