当前位置:网站首页>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
边栏推荐
- 修改Oracle连接数
- Detailed explanation of globalkey of flutter
- Matplotlib multi line chart, dot scatter chart
- CTF PHP audit bypasses filtering learning from topics
- Knowledge of SQL - database design, backup and restore
- What preparations should be made to develop an app from scratch
- Mutex of thread synchronization (mutex)
- [Nuggets' operation routine disclosure] the routine of being truly Nuggets
- Wechat applet is bound to a dynamic array to implement a custom radio box (after clicking the button, disable the button and enable other buttons)
- 线程同步之互斥量(互斥锁)
猜你喜欢

线程同步之读写锁
![[QT] dialog box](/img/ca/e65a0c167a4509f7c6a241870f6a32.png)
[QT] dialog box

What should I do if the 51 SCM board cannot find the device in keil

(15) Blender source code analysis flash window display menu function

Use soapUI to access the corresponding ESB project

Minecraft 1.16.5 生化8 模组 1.9版本 1.18版本同步

Nailing open platform - applet development practice (nailing applet client)

Install dbeaver and connect Clickhouse

How much do you make by writing a technical book? To tell you the truth, 2million is easy!

Getting started with flask
随机推荐
Review of number theory
Chrome page recording and playback function
Matplotlib multi line chart, dot scatter chart
[QT] dialog box
Dix critères de base importants pour les essais de débogage de logiciels
asp. Net web page, ASP connects to the database, and uses asp:panel and asp:dropdownlist controls
1064 (42000) error occurred when installing MySQL and modifying root password
Unity mobile game performance optimization spectrum CPU time-consuming optimization divided by engine modules
【QT】资源文件导入
Verrouillage de lecture et d'écriture pour la synchronisation des fils
Getting started with flask
Part 4: drawing quadrilateral
Double buffer technology asynchronous log system
How much do you make by writing a technical book? To tell you the truth, 2million is easy!
College C language final exam · multiple choice questions · summary notes of mistakes and difficulties
The stc-isp burning program for 51 single chip microcomputer always shows that "the target single chip microcomputer is being detected..." the cold start board does not respond
6、 Project practice --- identifying cats and dogs
[Nuggets' operation routine disclosure] the routine of being truly Nuggets
[Qunhui] no port access (reverse proxy + intranet penetration)
Lua语法讲解