最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does Date#getHours() return hour + 1? - Stack Overflow

programmeradmin1浏览0评论

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

Share Improve this question edited Jun 14, 2020 at 18:42 Edric 26.9k13 gold badges87 silver badges95 bronze badges asked Jan 15, 2014 at 10:30 markzzzmarkzzz 48.1k126 gold badges319 silver badges534 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

Because 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())
发布评论

评论列表(0)

  1. 暂无评论