当前位置:网站首页>Solution to the problem of PHP strtotime obtaining natural monthly error
Solution to the problem of PHP strtotime obtaining natural monthly error
2022-06-11 20:45:00 【The world is white_ I am the only one】
Differences in basic writing
for($i=1;$i<150;$i++){
$date = date('Y-m-d',strtotime("+{$i} day",strtotime('2022-01-25')));
echo $date.' >>> ';
// echo getNaturalMonth(-1,$date,true);
echo date('Y-m-d',strtotime('+1 month',strtotime($date)));
echo PHP_EOL;
}
Optimize the writing :
/**
* Get the next natural month date of a time
* @date 2022/5/31
* @param int $num Increase the number of months 1 Add one month -1 One month less
* @param null $date date
* @param bool $is_supplement If the current time is the last day of the current month, the new natural month will automatically return to the last day
* @return false|string|null
*/
function getNaturalMonth($num = 1,$date=null,$is_supplement = false)
{
$new_date = null;
$time = isset($date) ? strtotime($date): time();
$_time = strtotime($num.' month',$time);
$new_date = date('Y-m-d',$_time);
$new_day = date('d',$_time);
if($is_supplement == true && $new_day == date('t',$time)) { // Current date is the last day
$new_date = date('Y-m-t', strtotime('last day of ' . $num . ' month', $time));
} elseif($new_day != date('d',$time)){ // Judge whether the obtained month and day are the same as the current date
$new_date = date('Y-m-d',strtotime('last day of '.$num.' month',$time));
}
return $new_date;
}When $is_supplement = false when
2022-01-26 >>> 2022-02-26
2022-01-27 >>> 2022-02-27
2022-01-28 >>> 2022-02-28
2022-01-29 >>> 2022-02-28
2022-01-30 >>> 2022-02-28
2022-01-31 >>> 2022-02-28
2022-02-01 >>> 2022-03-01
2022-02-02 >>> 2022-03-02
2022-02-03 >>> 2022-03-03
2022-02-04 >>> 2022-03-04
2022-02-05 >>> 2022-03-05
2022-02-06 >>> 2022-03-06
2022-02-07 >>> 2022-03-07
2022-02-08 >>> 2022-03-08
2022-02-09 >>> 2022-03-09
2022-02-10 >>> 2022-03-10
2022-02-11 >>> 2022-03-11
2022-02-12 >>> 2022-03-12
2022-02-13 >>> 2022-03-13
2022-02-14 >>> 2022-03-14
2022-02-15 >>> 2022-03-15
2022-02-16 >>> 2022-03-16
2022-02-17 >>> 2022-03-17
2022-02-18 >>> 2022-03-18
2022-02-19 >>> 2022-03-19
2022-02-20 >>> 2022-03-20
2022-02-21 >>> 2022-03-21
2022-02-22 >>> 2022-03-22
2022-02-23 >>> 2022-03-23
2022-02-24 >>> 2022-03-24
2022-02-25 >>> 2022-03-25
2022-02-26 >>> 2022-03-26
2022-02-27 >>> 2022-03-27
2022-02-28 >>> 2022-03-28
2022-03-01 >>> 2022-04-01
2022-03-02 >>> 2022-04-02
2022-03-03 >>> 2022-04-03
2022-03-04 >>> 2022-04-04
2022-03-05 >>> 2022-04-05
2022-03-06 >>> 2022-04-06
2022-03-07 >>> 2022-04-07
2022-03-08 >>> 2022-04-08
2022-03-09 >>> 2022-04-09
2022-03-10 >>> 2022-04-10
2022-03-11 >>> 2022-04-11
2022-03-12 >>> 2022-04-12
2022-03-13 >>> 2022-04-13
2022-03-14 >>> 2022-04-14
2022-03-15 >>> 2022-04-15
2022-03-16 >>> 2022-04-16
2022-03-17 >>> 2022-04-17
2022-03-18 >>> 2022-04-18
2022-03-19 >>> 2022-04-19
2022-03-20 >>> 2022-04-20
2022-03-21 >>> 2022-04-21
2022-03-22 >>> 2022-04-22
2022-03-23 >>> 2022-04-23
2022-03-24 >>> 2022-04-24
2022-03-25 >>> 2022-04-25
2022-03-26 >>> 2022-04-26
2022-03-27 >>> 2022-04-27
2022-03-28 >>> 2022-04-28
2022-03-29 >>> 2022-04-29
2022-03-30 >>> 2022-04-30
2022-03-31 >>> 2022-04-30
2022-04-01 >>> 2022-05-01
2022-04-02 >>> 2022-05-02
2022-04-03 >>> 2022-05-03
2022-04-04 >>> 2022-05-04
2022-04-05 >>> 2022-05-05
2022-04-06 >>> 2022-05-06
2022-04-07 >>> 2022-05-07
2022-04-08 >>> 2022-05-08
2022-04-09 >>> 2022-05-09
2022-04-10 >>> 2022-05-10
2022-04-11 >>> 2022-05-11
2022-04-12 >>> 2022-05-12
2022-04-13 >>> 2022-05-13
2022-04-14 >>> 2022-05-14
2022-04-15 >>> 2022-05-15
2022-04-16 >>> 2022-05-16
2022-04-17 >>> 2022-05-17
2022-04-18 >>> 2022-05-18
2022-04-19 >>> 2022-05-19
2022-04-20 >>> 2022-05-20
2022-04-21 >>> 2022-05-21
2022-04-22 >>> 2022-05-22
2022-04-23 >>> 2022-05-23
2022-04-24 >>> 2022-05-24
2022-04-25 >>> 2022-05-25
2022-04-26 >>> 2022-05-26
2022-04-27 >>> 2022-05-27
2022-04-28 >>> 2022-05-28
2022-04-29 >>> 2022-05-29
2022-04-30 >>> 2022-05-30
2022-05-01 >>> 2022-06-01
When $is_supplement =true when
2022-01-26 >>> 2022-02-26
2022-01-27 >>> 2022-02-27
2022-01-28 >>> 2022-02-28
2022-01-29 >>> 2022-02-28
2022-01-30 >>> 2022-02-28
2022-01-31 >>> 2022-02-28
2022-02-01 >>> 2022-03-01
2022-02-02 >>> 2022-03-02
2022-02-03 >>> 2022-03-03
2022-02-04 >>> 2022-03-04
2022-02-05 >>> 2022-03-05
2022-02-06 >>> 2022-03-06
2022-02-07 >>> 2022-03-07
2022-02-08 >>> 2022-03-08
2022-02-09 >>> 2022-03-09
2022-02-10 >>> 2022-03-10
2022-02-11 >>> 2022-03-11
2022-02-12 >>> 2022-03-12
2022-02-13 >>> 2022-03-13
2022-02-14 >>> 2022-03-14
2022-02-15 >>> 2022-03-15
2022-02-16 >>> 2022-03-16
2022-02-17 >>> 2022-03-17
2022-02-18 >>> 2022-03-18
2022-02-19 >>> 2022-03-19
2022-02-20 >>> 2022-03-20
2022-02-21 >>> 2022-03-21
2022-02-22 >>> 2022-03-22
2022-02-23 >>> 2022-03-23
2022-02-24 >>> 2022-03-24
2022-02-25 >>> 2022-03-25
2022-02-26 >>> 2022-03-26
2022-02-27 >>> 2022-03-27
2022-02-28 >>> 2022-03-31
2022-03-01 >>> 2022-04-01
2022-03-02 >>> 2022-04-02
2022-03-03 >>> 2022-04-03
2022-03-04 >>> 2022-04-04
2022-03-05 >>> 2022-04-05
2022-03-06 >>> 2022-04-06
2022-03-07 >>> 2022-04-07
2022-03-08 >>> 2022-04-08
2022-03-09 >>> 2022-04-09
2022-03-10 >>> 2022-04-10
2022-03-11 >>> 2022-04-11
2022-03-12 >>> 2022-04-12
2022-03-13 >>> 2022-04-13
2022-03-14 >>> 2022-04-14
2022-03-15 >>> 2022-04-15
2022-03-16 >>> 2022-04-16
2022-03-17 >>> 2022-04-17
2022-03-18 >>> 2022-04-18
2022-03-19 >>> 2022-04-19
2022-03-20 >>> 2022-04-20
2022-03-21 >>> 2022-04-21
2022-03-22 >>> 2022-04-22
2022-03-23 >>> 2022-04-23
2022-03-24 >>> 2022-04-24
2022-03-25 >>> 2022-04-25
2022-03-26 >>> 2022-04-26
2022-03-27 >>> 2022-04-27
2022-03-28 >>> 2022-04-28
2022-03-29 >>> 2022-04-29
2022-03-30 >>> 2022-04-30
2022-03-31 >>> 2022-04-30
2022-04-01 >>> 2022-05-01
2022-04-02 >>> 2022-05-02
边栏推荐
- 27. this pointing problem
- 2022-2028 global and Chinese thermal ionization isotope mass spectrometer (TIMS) market status and future development trend
- R 16 basic exercises
- The input value "18-20000hz" is incorrect. The setting information is incomplete. Please select a company
- Object storage of CEPH distributed storage
- Product information | Poe network card family makes a collective appearance, the perfect partner of machine vision!
- Calculation of Zeno paradox
- [nk] 牛客练习赛100 C 小红的删数字
- Implement AOP and interface caching on WPF client
- Using the flask framework to write the bezel
猜你喜欢

moderlarts第二次作业

In unity, opencv and QT are used to create a plugin (I)

银泰百货与淘宝天猫联合打造绿色潮玩展,助力“碳中和”

Black circle display implementation

新品发布:国产单电口千兆网卡正式量产!

First modelarts training

unity package manager starting server stuck(Unity启动卡在starting server,然后报错)
![[nk] 牛客练习赛100 C 小红的删数字](/img/f1/a99600e1800c087aceb60a559dee39.png)
[nk] 牛客练习赛100 C 小红的删数字

MySQL installation free configuration tutorial under Windows mysql-5.6.51-winx64 Zip version
![[data visualization] Apache superset 1.2.0 tutorial (III) - detailed explanation of chart functions](/img/1f/00f2085186971198928b012a3792ea.jpg)
[data visualization] Apache superset 1.2.0 tutorial (III) - detailed explanation of chart functions
随机推荐
Introduction to jobrunr, a distributed background job scheduler - jaxenter
Two end carry output character
Redis fourth session - redis high performance principle (multiplexing) and high availability analysis (backup, master-slave)
Windows icon display exception resolution. The desktop icon is abnormal, the start menu icon is abnormal, and the taskbar icon is abnormal. Icon cache location.
Ubantu1804 two opencv versions coexist
Js 监听滚动触底加载更多_浏览器滚动触底加载更多
Chinese text classification based on CNN
9 r remove missing values
Current situation and future development trend of hot isostatic pressing service market in the world and China from 2022 to 2028
2022-2028 current situation and future development trend of fuel cell market for cogeneration application in the world and China
12 date and time in R
QQ贴吧那种图片一点开,就变了的原理
A mechanics informed artistic neural network approach in data driven constructive modeling
27. this pointing problem
Toolbar替换ActionBar后Title不显示
Current situation and future development trend of thermoelectric generator Market in the world and China from 2022 to 2028
14 r basic exercises
Capriccio in the Internet Age
R 16 basic exercises
Research and Analysis on the market status of polybutene-1 in China from 2021 to 2027 and forecast report on its development prospect