当前位置:网站首页>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;
}
}边栏推荐
- ctfshow web 1-2
- Bean的作用域
- Hands on deep learning -- implementation of multi-layer perceptron from scratch and its concise implementation
- Project sorting of niuke.com
- [compilation principle] understand BNF
- Calling stored procedures in mysql, definition of variables,
- Ankerui motor protector has the functions of overload inverse time limit, overload definite time limit, grounding, starting timeout, leakage, underload, phase failure, locked rotor, etc
- Error: clear the history in the search box in the website?
- Arrays in JS
- Build personal blog and web.
猜你喜欢
![[essence] explain in detail the memory management mechanism in QT](/img/7d/0d83158c6b0574dd3b3547b47af67e.jpg)
[essence] explain in detail the memory management mechanism in QT
![Easyexcel exports excel tables to the browser, and exports excel through postman test [introductory case]](/img/ca/0e2bd54a842a393231ec6db5ab02c2.png)
Easyexcel exports excel tables to the browser, and exports excel through postman test [introductory case]

Hands on deep learning -- activation function and code implementation of multi-layer perceptron

Model compression | tip 2022 - Distillation position adaptation: spot adaptive knowledge distillation
![[new planning]](/img/8e/0e15e0f3ee08002eaceea1fe8948ec.jpg)
[new planning]

【进阶指针二】数组传参&指针传参&函数指针&函数指针数组&回调函数

根据有效期显示距离当前还剩多少天有效期

Loading font component loading effect

【指針進階三】實現C語言快排函數qsort&回調函數

FDA审查人员称Moderna COVID疫苗对5岁以下儿童安全有效
随机推荐
电气火灾探测器对各用电回路进行实时监控
Loading circling effect during loading
Regular verification user name
Error: what if the folder cannot be deleted when it is opened in another program
The residual pressure monitoring system ensures the smoothness of the fire evacuation passage in case of fire, and protects the safe operation of large high-rise buildings and the safety of people's l
The difference between deep copy and shallow copy
【指针进阶三】实现C语言快排函数qsort&回调函数
报错:文件夹在另一个程序中打开无法删除怎么办
call方法和apply方法
Ankerui fire emergency lighting and evacuation indication system
Engineers learn music theory (II) scale and tendency
(P13) use of final keyword
[essence] explain in detail the memory management mechanism in QT
X64dbg debugging exception_ ACCESS_ VIOLATION C0000005
动态线段树leetcode.699
(p33-p35) lambda expression syntax, precautions for lambda expression, essence of lambda expression
Figure neural network makes Google maps more intelligent
ctfshow web4
MSTP的配置与原理
Principle and configuration of MPLS