当前位置:网站首页>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';
}
边栏推荐
- Circuitbreaker fuse of resilience4j - circuitbreakerevent event
- Oculus quest generation opens Bluetooth connection
- Wechat payment, wechat refund, Alibaba payment
- ID obfuscation
- 数组,整型,字符变量在全局和局部的存在形式
- Data processing and visualization of machine learning [iris data classification | feature attribute comparison]
- [CEGUI] font resource loading process
- Machine learning is not something you can use if you want to use it
- Redis (II) Memory mapped data structure
- 一测两三年,记测试交流经验的一些感想
猜你喜欢

远程桌面不能复制粘贴解决办法
![[CEGUI] resource loading process](/img/52/819843db21549b5e5031258f2c5cb0.jpg)
[CEGUI] resource loading process

ASP.NET Core权限系统实战(零)

The solution of Lenovo notebook ThinkPad t440 WiFi dropping all the time

How high can C language reach by self-study alone?

Leetcdoe 2037. 使每位学生都有座位的最少移动次数(可以,一次过)

How to refund the pre-sale deposit of JD 618 in 2022? Can JD 618 deposit be refunded?

The solution of Lenovo notebook ThinkPad t440 WiFi unable to connect to the Internet

Class. Forname connection MySQL driver keeps throwing classnotfoundexception exception solution

Love and hate in the Jianghu
随机推荐
Binassii module - converting between binary and ASCII
Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)
Properties Chinese garbled code
数组,整型,字符变量在全局和局部的存在形式
4. creator mode
ASP.NET Core权限系统实战(零)
Find the location of a function in PHP
验收标准到底是不是测试用例?
Circuitbreaker fuse of resilience4j - circuitbreakerevent event
PHP wechat red packet allocation logic
不需要安装防毒软件的系统Chromebook
ID obfuscation
JVM (VI) Virtual machine bytecode execution engine (with stack execution process and bytecode instruction table)
Love and hate in the Jianghu
A hundred secrets and a few secrets - Caesar encryption
Dynamic proxy
Getting started with cloud API basics -- basic knowledge of picgo writing plug-ins
[Wayland] Wayland introduction and customized guidance
Leetcode 2169. 得到 0 的操作数
PHP occupies memory