当前位置:网站首页>JS obtains the time period of this week and last week (one time period is from Monday to Sunday)
JS obtains the time period of this week and last week (one time period is from Monday to Sunday)
2022-06-12 10:29:00 【Zi Jiao】
Due to business needs, get this week 、 Last week period , Originally lazy to write , Search the Internet , Many seats are not in a time cycle from Monday to Sunday , Then I wrote down .
/*************************************
* Get this Monday
* It is a time period from Monday to Sunday
* var d = new Date();
* d.getFirstDayOfWeek(lastWeekNum);
* @param lastWeekNum tinyint The number of days subtracted from this Sunday , Is empty or 0, Get this Monday 00:00:00
*************************************/
Date.prototype.getFirstDayOfWeek = function(lastWeekNum) {
var d = (new Date(this.setDate(this.getDate() - this.getDay()+ (this.getDay() == 0 ? -6:1) )));
if (lastWeekNum) {
if (isNaN(lastWeekNum)) lastWeekNum = 7;
d = d.setDate(d.getDate()-lastWeekNum);
d = new Date(d);
}
return d.getFullYear()+'-'+ (d.getMonth()+1) +'-'+ d.getDate()+' 00:00:00';
}
/*************************************
* Get this Sunday
* It is a time period from Monday to Sunday
* var d = new Date();
* d.getLastDayOfWeek(lastWeekNum);
* @param lastWeekNum tinyint The number of days subtracted from this Sunday , Is empty or 0, Get this Sunday 23:59:59
*************************************/
Date.prototype.getLastDayOfWeek = function(lastWeekNum) {
var d = (new Date(this.setDate(this.getDate() - this.getDay() +7)));
if (lastWeekNum) {
if (isNaN(lastWeekNum)) lastWeekNum = 7;
d = d.setDate(d.getDate()-lastWeekNum);
d = new Date(d);
}
return d.getFullYear() +'-'+ (d.getMonth()+1) +'-'+ d.getDate()+' 23:59:59';
}
边栏推荐
- A hundred secrets and a few secrets - Caesar encryption
- 淺談調和形狀上下文特征HSC對3DSC的改進
- How Qualcomm platform modifies special voltage
- The name of a great man
- [Wayland] Wayland introduction and customized guidance
- Circuitbreaker fuse of resilience4j - circuitbreakerconfig configuration
- Find the location of a function in PHP
- 在一个“去QA化”的项目中,QA能做什么?
- Solution to the problem that the applet developer tool cannot input simplified Chinese
- Cookie object
猜你喜欢

2022 Taobao 618 Super Cat Games introduction 618 super cat games playing skills
![[CEGUI] window environment compilation](/img/be/0413fc876ffbbd40371469eee06f01.jpg)
[CEGUI] window environment compilation
![[DDS] ddsi-rtps specification](/img/fe/16b835e3e4a8ff71ab3dbc4b9c4d2a.jpg)
[DDS] ddsi-rtps specification

2022京東618預售定金怎麼退?京東618定金能退嗎?
![[MySQL] index invalidation and index optimization](/img/af/9ed540aab764f4962ccc9bbfe406f3.jpg)
[MySQL] index invalidation and index optimization

2022淘宝618超级喵运会怎么玩?2022淘宝618喵运会玩法技巧
![[Wayland] Weston startup process analysis](/img/0e/24f374144ea7ea762a83f6598ebd48.jpg)
[Wayland] Weston startup process analysis
SAP Hana error message sys_ XSA authentication failed SQLSTATE - 28000

tp6调试(trace)

Amélioration de la 3dsc par HSC
随机推荐
Composer command
One test for twoorthree years, recording some thoughts on test exchange experience
Remote desktop cannot copy and paste solution
Raw socket usage
Mysql5.6.24 installation free deployment method
How to refund the pre-sale deposit of JD 618 in 2022? Can JD 618 deposit be refunded?
[MySQL] index invalidation and index optimization
The difference between static method locking and non static method locking
Download Notepad++
Download Notepad++
Win10 professional edition user name modification
Circuitbreaker fuse of resilience4j - circuitbreakerregistry register
2022京东618预售定金怎么退?京东618定金能退吗?
[DDS] dds-rpc implementation based on opendds
Circuitbreaker fuse of resilience4j - circuitbreakerconfig configuration
Solution to the problem that the applet developer tool cannot input simplified Chinese
Tp6+memcached configuration
Leetcdoe 2037. 使每位学生都有座位的最少移动次数(可以,一次过)
性能指标的信仰危机
SAP Hana error message sys_ XSA authentication failed SQLSTATE - 28000