转载请注明出处: http://qiudeqing.com/javascript/2015/09/09/date.html

获取今天0时

var now = new Date();

var dayMill = 1000 * 60 * 60 * 24;

var beginMill = Math.floor(now.getTime() / day) * day;
var begin = new Date(beginMill);

上面的begin是UTC标准的当天0时, 在北京时间显示的是早上八点, 如果需要获取北京时间0时, 需要加上时区差:

var beginMill = Math.floor(now.getTime() / day) * day
  + now.getTimezoneOffset() * 60 * 1000;
var begin = new Date(beginMill);

获取明天0时

在前面今天0时的基础上加上一天的毫秒数即可

var tomorrowMill = beginMill + dayMill;
var tomorrowBegin = new Date(tomorrowMill);