0

今天是 2013 年 10 月 18 日

var tmp = new Date('2013-10-18');
    tmp = tmp.getTime();

1382054400000 (格林威治标准时间:格林威治标准时间 2013 年 10 月 18 日星期五 00:00:00)

var today = new Date();
    today = today.setHours(0,0,0,0);

1382047200000 (格林威治标准时间:格林威治标准时间 2013 年 10 月 17 日星期四 22:00:00)


.setHours(0,0,0,0)不将日期设置为午夜 (00:00:00) 吗?

4

1 回答 1

1

Date.setHours将在您当前的时区中将时间设置为“00:00:00:00”。

Sets the hours for a specified date according to local time, and returns the number of milliseconds since 1 January 1970 00:00:00 UTC until the time represented by the updated Date instance.

如果您想以 UTC 时间工作,请改用Date.setUTCHours

于 2013-10-18T08:52:27.823 回答