当前位置:网站首页>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;
}
}边栏推荐
- 2022.6.11-----leetcode.926
- Engineers learn music theory (I) try to understand music
- Graphic analysis of viewbox in SVG
- API处理Android安全距离
- Only use MES as a tool? Looks like you missed the most important thing
- 【数据存储】浮点型数据在内存中的存储
- Oracle installation details (verification)
- QT realizes multi screen and multi-resolution adaptation
- Configuration and principle of MSTP
- 安科瑞电动机保护器具有过载反时限、过载定时限、接地、起动超时、漏电、欠载、断相、堵转等功能
猜你喜欢

(p21-p24) unified data initialization method: List initialization, initializing objects of non aggregate type with initialization list, initializer_ Use of Lisy template class

调整svg宽高

Error: clear the history in the search box in the website?

MSTP的配置与原理

js中的正则表达式

X64dbg debugging exception_ ACCESS_ VIOLATION C0000005

Hands on learning and deep learning -- simple implementation of linear regression

Installation series of ROS system (I): installation steps

Display the remaining valid days according to the valid period

Asp Net project add log function
随机推荐
[GUI development] browsing function implementation model of image processing software
Beidou satellite navigation system foundation part 1
三国杀周边--------猪国杀题解
Model compression | tip 2022 - Distillation position adaptation: spot adaptive knowledge distillation
Installation series of ROS system (I): installation steps
【新规划】
Oracle installation details (verification)
Figure neural network makes Google maps more intelligent
ctfshow web 1-2
[advanced pointer III] implement C language quick sorting function qsort & callback function
电气火灾探测器对各用电回路进行实时监控
Centso8 installing mysql8.0 (Part 2)
判断对象是否为空
Hands on deep learning -- image classification dataset fashion MNIST
根据有效期显示距离当前还剩多少天有效期
Configuration and principle of MSTP
报错:清除网站内搜索框中的历史记录?
调整svg宽高
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
Triggers in MySQL