当前位置:网站首页>Get last month, current time and next month
Get last month, current time and next month
2022-06-12 08:40:00 【Pumpkin_ xiaoXuan】
function getXmonthToday(type) {
// type 0 It's the same day -1 It was last month 1 It's next month
var now = new Date(); // You can transfer the value mode now = new Date(2019,2,30); It's today 3 month 30 Number
var year = now.getFullYear();//getYear()+1900=getFullYear()
var month = now.getMonth() + 1;//0-11 Express 1-12 month
var day = now.getDate(); // Date of the day
if (parseInt(month) < 10) {
month = "0" + month;
}
if (parseInt(day) < 10) {
day = "0" + day;
}
now = year + '-' + month + '-' + day; // If you take the date of the current month, you can directly return return
var preMonth = parseInt(month) - 1;
preMonth = preMonth < 10 ? '0' + preMonth : preMonth; // Get the value of last month
var nextMonth = parseInt(month) + 1;
nextMonth = nextMonth < 10 ? '0' + nextMonth : nextMonth; // Get the value of the next month
if (parseInt(month) == 1 && type == -1) {// If it is 1 month , Last month , Take the last year's 12 month
return (parseInt(year) - 1) + '-12-' + day;
} else if (parseInt(month) == 12 && type == 1) { // If it is 12 month , Next month , Take the next year's 1 month
return (parseInt(year) + 1) + '-01-' + day;
}
var preSize = new Date(year, parseInt(month) - 1, 0).getDate();// Total number of days in the previous month
var nextSize = new Date(year, parseInt(month)+ 1, 0).getDate();// Total number of days in the next month
console.log(preSize, nextSize)
if (preSize < parseInt(day) && type == -1) {// Take last month , If the total number of days in the previous month is less than today in this month , Take the last day of last month
return year + '-' + preMonth + '-' + preSize;
} else if (nextSize < parseInt(day) && type == 1) { // If the total number of days in the next month is less than today in this month , Take the last day of the month
return year + '-' + nextMonth + '-' + nextSize;
}
if (type == -1) {
return year + '-' + preMonth + '-' + day;
} else if (type == 1) {
return year + '-' + nextMonth + '-' + day;
}else if(type == 0){
return now;
}
}边栏推荐
- What is the beauty of MES equipment management for enterprises?
- What kind of sparks will be generated when the remote sensing satellite meets the Beidou navigation satellite?
- 2022.6.9-----leetcode.497
- (p27-p32) callable object, callable object wrapper, callable object binder
- Dynamic segment tree leetcode six hundred and ninety-nine
- Handling abnormal data
- In the era of intelligent manufacturing, how do enterprises carry out digital transformation
- Hands on deep learning -- Introduction to linear regression model
- Hands on deep learning 18 -- model selection + over fitting and under fitting and code implementation
- At present, MES is widely used. Why are there few APS scheduling systems? Why?
猜你喜欢

Hands on deep learning -- image classification dataset fashion MNIST

Hands on learning and deep learning -- Realization of linear regression from scratch

电气火灾探测器对各用电回路进行实时监控
![[compilation principle] understand BNF](/img/64/9a0e7507606781336fdc44116ba423.jpg)
[compilation principle] understand BNF

网站Colab与Kaggle

【数据存储】浮点型数据在内存中的存储

FDA reviewers say Moderna covid vaccine is safe and effective for children under 5 years of age

Hands on deep learning -- concise implementation code of weight decay

余压监控系统保证火灾发生时消防疏散通道的通畅,为大型高层建筑的安全运行和人民生命财产安全保驾护航

Ankerui fire emergency lighting and evacuation indication system
随机推荐
Display the remaining valid days according to the valid period
在Tensorflow中把Tensor转换为ndarray时,循环中不断调用run或者eval函数,代码运行越来越慢!
Query in MySQL
Centso8 installing mysql8.0 (Part 2)
You have an error in your SQL syntax; use near ‘and title=‘xxx‘‘ at line 5
(p33-p35) lambda expression syntax, precautions for lambda expression, essence of lambda expression
Difference between binary GB and gib
Engineers learn music theory (I) try to understand music
Dynamically create and submit forms
Hands on deep learning -- Introduction to linear regression model
The Three Kingdoms kill the surrounding areas -------- explanation of the pig Kingdom kill problem
Loading circling effect during loading
Arrays in JS
ctfshow web 1-2
The difference between deep copy and shallow copy
MYSQL中的调用存储过程,变量的定义,
Loading font component loading effect
调整svg宽高
In depth interpretation of 5g key technologies
(p21-p24) unified data initialization method: List initialization, initializing objects of non aggregate type with initialization list, initializer_ Use of Lisy template class