确定当天的开始和结束时间(UTC)(JAVASCRIPT)

时间:2015-09-06 02:04:25

标签: javascript utc

我正在尝试以UTC格式确定当天的开始和结束时间。

目前这是我的解决方案。 `

var starttime = date.getTime() -(date.getHours() * 3600000 ); //subtracting a hours to go back to start time of the day.
var endtime = low + 86400000; //adding 24 hours to the start time 
   `

任何帮助表示赞赏!谢谢

2 个答案:

答案 0 :(得分:4)

谢谢大家。这对我有用!! :)

 var d = new Date();
 var year = d.getUTCFullYear();
 var month = d.getUTCMonth();
 var day = d.getUTCDate();

 var startHour =Date.UTC(year,month,day,0,0,0,0);
 var endHour = startHour + 86400000;

答案 1 :(得分:0)

这已在这里得到解答: How to get start and end of day in Javascript?

var start = Date.UTC();
start.setHours(0,0,0,0);

var end = Date.UTC();
end.setHours(23,59,59,999);

alert( start.toUTCString() + ':' + end.toUTCString() );