当前位置:网站首页>JS take the date of the previous month 【 pit filling 】
JS take the date of the previous month 【 pit filling 】
2022-06-26 10:46:00 【Pig man blogs】
When working on writing code , There is a place to be based on years As a query condition
- First of all new Date() get date object
- Reuse his set Method , Will be set go in

var date = new Date();
date.setFullYear(2019);
date.setMonth(10); -- Here month The scope is (0~11), Explain that I am now set to 11 month
Then I think it should be 2019-11 The object of this date however !!!
There is a ghost .. The return is 2019-12-01( The second line )

……
- Toss and turn for a long time , Still failed , Suddenly I see that today is 2019-12-31

I was thinking , It is the new year , I am still in vain , I didn't learn anything , It's hard. It's hard ... But ,,, Why ---- incorrect !
If today is 31 Number , This is me. date Is it difficult to set it to 2019-11-31 了 ?( Because I only set the year and month , Day is not set , So the day should be the initialization time )
When you find a problem , I started searching for information again

https://www.cnblogs.com/jc2182/p/11273954.html
Unfortunately, there is no way to set the day , This method should not work
- Continue Baidu's other methods online , Finally, I found a brother's way ( Direct use of construction methods )
/** * Get the last month end date */
function getLastMonthAndDay(){
var nowDate = new Date();
var year = nowDate.getFullYear();
var month = nowDate.getMonth(); if(month == 0){
month = 12;
year = year - 1;
}
var lastDay = new Date(year,month,0);
var yyyyMMdd = year+" year "+month+" month "+lastDay.getDate()+" Japan ";
console.log(yyyyMMdd);
}
var lastDay = new Date(year,month,0); You can directly set the month and year you want
边栏推荐
- MySQL第八次作业
- Call API interface to generate QR code of wechat applet with different colors
- Search engine advanced search method records
- 挖财商学院证券开户安全嘛?
- Global and Chinese markets in hair conditioner 2022-2028: Research Report on technology, participants, trends, market size and share
- Oracle11g reports an error when starting the database ora-27154: post/wait create failed
- Using reflection to export entity data to excel
- Getting started with postman
- MySQL Chapter 6 Summary
- Oracle11g 启动数据库时报错 ORA-27154: post/wait create failed
猜你喜欢

Selection of webrtc video codec type VP8 H264 or other? (openh264 encoding, ffmpeg decoding)

Express (I) - easy to get started

Which PHP open source works deserve attention

看我在Map<String, String>集合中,存入Integer类型数据

Reshape a two-dimensional array with 3 rows and 3 columns to find the sum of the diagonals

SwiftUI 开发经验之为离线优先的应用程序设计数据层

ISO 26262之——2功能安全概念

【软件项目管理】期末复习知识点整理

See how I store integer data in the map < string, string > set

Call API interface to generate QR code of wechat applet with different colors
随机推荐
MySQL第十三次作业-事务管理
Execute Lua script in redis
MySQL Chapter 4 Summary
Global and Chinese market of cryogenic bulk tanks 2022-2028: Research Report on technology, participants, trends, market size and share
Concise course of probability theory and statistics in engineering mathematics second edition review outline
Hcia-dhcp experiment
AIX基本操作记录
利用foreach循环二维数组
Blog article index Summary - wechat games
栖霞市住建局和消防救援大队开展消防安全培训
Windows and Linux regularly backup MySQL database
[echart] i. how to learn echart and its characteristic document reading notes
Matrix fast power notes
Reshape a two-dimensional array with 3 rows and 3 columns to find the sum of the diagonals
Opencv image processing - grayscale processing
Flutter and native communication (Part 1)
Blog post index summary --c #
Quantitative investment learning - Introduction to classic books
MySQL 13th job - transaction management
哪些PHP开源作品值得关注