JS 根据今天的日期获取本周星期一与星期天的日期

Anonymity | | 访问(52)
var now = new Date();
var nowTime = now.getTime();
var day = now.getDay();
var oneDayLong = 24 * 60 * 60 * 1000;

var MondayTime = nowTime - (day - 1) * oneDayLong;
var SundayTime = nowTime + (7 - day) * oneDayLong;

var monday = new Date(MondayTime);
var sunday = new Date(SundayTime);
console.log(monday);
console.log(sunday);