【js】js获取今日和昨日0点和23点59分59秒

1.今日0点和23时59分59秒

//方式1
const end = new Date(new Date().toLocaleDateString());
const start = new Date(new Date().toLocaleDateString());
start.setTime(start.getTime());
end.setTime(end.getTime() + 3600 * 1000 * 24 - 1000)
//方式2
const start  = new Date();
start.setHours(0);
start.setMinutes(0);
start.setSeconds(0);
start.setMilliseconds(0);

const end = new Date(start + 3600*1000*24 -1000)

2.昨日0点和23时59分59秒

 const today = new Date();
 today.setHours(0);
  today.setMinutes(0);
  today.setSeconds(0);
  today.setMilliseconds(0);
  const end = new Date(today - 1000);
  const start = new Date(today - 3600*1000*24);

你可能感兴趣的:(js,js)