当前位置:网站首页>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
边栏推荐
- [Qunhui] command line acme SH automatically apply for domain name certificate
- 线程同步之读写锁
- [从零开始学习FPGA编程-45]:视野篇 - 集成电路助力数字化时代高质量发展-2-市场预测
- What preparation should I make before learning SCM?
- MySQL est livré avec l'outil de test de performance MySQL lap pour effectuer des tests de résistance
- 1.基础关
- 力扣 515. 在每个树行中找最大值
- WPF 值转换
- 2021 year end summary
- Li Kou 79 word search
猜你喜欢

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

Ubuntu installs PostgreSQL and uses omnidb to view

Verrouillage de lecture et d'écriture pour la synchronisation des fils

Spark - 一文搞懂 parquet

Detr3d multi 2D picture 3D detection framework

Construction of art NFT trading platform | NFT mall

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

win10 系统打开的软件太小,如何变大(亲测有效)

Redis cache data consistency solution analysis

After a test of 25K bytes, I really saw the basic ceiling
随机推荐
Verrouillage de lecture et d'écriture pour la synchronisation des fils
CTF serialization and deserialization
[learn FPGA programming from scratch -45]: vision chapter - integrated circuits help high-quality development in the digital era -2- market forecast
[QT] dialog box
Sorting out the examination sites of the 13th Blue Bridge Cup single chip microcomputer objective questions
Install dbeaver and connect Clickhouse
Resolve PHP is not an internal or external command
Spark - understand parquet
钉钉开放平台-小程序开发实战(钉钉小程序服务器端)
[从零开始学习FPGA编程-45]:视野篇 - 集成电路助力数字化时代高质量发展-2-市场预测
SQL related knowledge - DQL
Read / write lock for thread synchronization
College C language final exam · multiple choice questions · summary notes of mistakes and difficulties
MySQL's built-in performance testing tool, mysqlslap, performs stress testing
Mutex of thread synchronization (mutex)
VHDL设计
Threejs special sky box materials, five kinds of sky box materials are downloaded for free
R language and machine learning
Getter actual combat geTx tool class encapsulation -getutils
CDN with OSS acceleration