当前位置:网站首页>Gets the time range of the current week

Gets the time range of the current week

2022-04-23 17:41:00 Front Thoughts

demand : The background needs to receive the time range of the current day !

Get the day of the week that the current day is :

var now = new Date(); 
var nowTime = now.getTime() ; 
var day = now.getDay();
var oneDayTime = 24*60*60*1000 ;

Get the Monday of the current week :

var MondayTime = nowTime - (day-1)*oneDayTime ;

Get the Sunday of the current week :

var SundayTime =  nowTime + (7-day)*oneDayTime ;

Initialization date time and parsing time format :

var monday = new Date(MondayTime).toISOString().slice(0,10).replace(/-/g,"/");
var sunday = new Date(SundayTime).toISOString().slice(0,10).replace(/-/g,"/");

Encapsulate the corresponding common.js Library to directly call , The callback returns the time of Monday Note the format of the conversion date :

function getFirstDayOfWeek (date) {
    
    var day = date.getDay() || 7;
    return new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1 - day);
};

 Insert picture description here

版权声明
本文为[Front Thoughts]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230551157187.html