当前位置:网站首页>PHP has the problem of using strtotime to obtain time in months and months [original]
PHP has the problem of using strtotime to obtain time in months and months [original]
2022-06-26 04:19:00 【Telkobe】
Use strtotime Time acquisition is used very frequently in daily work , However, there is a problem of months and months when we get the time , When the number of days is not extreme, we generally do not pay attention to , However, the day just happens to be the last day of the month, and unexpected situations may occur
for instance :
echo date('Y-m-d',strtotime('+1 month 2020-1-31'));The result of the above code is :2020-03-02, I don't think this is the result we want , What we want is 2 On the last day of the month , So what is the reason for this , as a result of +1 month Words strtotime It is equivalent to operating the number of months , The result is 2020-2-31, however 2 The month did not 31 God ,2020 year 2 Month only 29 God , Two more days , So I am tired till next month , Then we get 2020-03-02 This result , How to solve it , Need to be in +1month Add a paragraph before :last day of;PS:php Version required >=5.3
echo date('Y-m-d',strtotime('last day of +1 month 2020-1-31'));So we get the result we want :2020-02-29
边栏推荐
- Video label forbids downloading. The test is valid. Hide button. The test is valid at three points
- R language and machine learning
- Install dbeaver and connect Clickhouse
- Database related knowledge
- 【掘金运营套路揭露】真心被掘金的套路....
- 【QT】对话框dialog
- 力扣 515. 在每个树行中找最大值
- go语言泛型在IDE中语法报错
- Analysis report on the development trend and operation status of China's environmental monitoring instrument industry from 2022 to 2028
- Zeromq from getting started to mastering
猜你喜欢

Ubuntu installs PostgreSQL and uses omnidb to view

The statistics in the MySQL field become strings, and then they are converted into numbers for sorting

6、 Project practice --- identifying cats and dogs

How to use EEPROM in 51 Single Chip Microcomputer?

Sorting out the examination sites of the 13th Blue Bridge Cup single chip microcomputer objective questions

Redis cache data consistency solution analysis

【QT】对话框dialog

35 year old programmer fired Luna millions of assets and returned to zero in three days. Netizen: it's the same as gambling

钉钉开放平台-小程序开发实战(钉钉小程序服务器端)

Matplotlib line chart, text display, win10
随机推荐
English version of ternary loss
MySQL index details
Computer network high frequency interview questions
CTF PHP audit bypasses filtering learning from topics
Principle and implementation of syn cookie
Force buckle 515 Find the maximum value in each tree row
WPF 值转换
After four years of outsourcing, people are directly abandoned...
Part 4: drawing quadrilateral
I/o virtualization technology - UIO framework
Judge the same value of two sets 𞓜 different values
Spark - 一文搞懂 parquet
Analysis of updatechild principle of widget update mechanism of fluent
Capture packets (Wireshark)
SQL related knowledge - DQL
Threejs专用天空盒素材,五种天空盒素材免费下载
Install cenos in the virtual machine
Construction of art NFT trading platform | NFT mall
Parse JSON interface and insert it into the database in batch
Detr3d multi 2D picture 3D detection framework