简体   繁体   English

strtotime 因新年(2022 年)的变化而停止工作

[英]strtotime stopped working with change of new year (2022)

I have the following piece of code to find next month, if before the 20th, and two months out, if after the 20th.如果在 20 日之前,我有以下代码要在下个月找到,如果在 20 日之后,则需要两个月。 Then it converts the month number to a character.然后它将月份数字转换为字符。

Before January 2022 I was able to get the number of the month using在 2022 年 1 月之前,我能够使用

$month =  strtotime($current_month);

After some searching around I got it working by changing that piece of code to经过一番搜索后,我通过将那段代码更改为

$month = date_format($current_month, 'm');

Any help as to why it stopped working or if the date_format is the proper way to go would be greatly appreciated.关于它为什么停止工作或date_format是否是 go 的正确方法的任何帮助将不胜感激。 Thanks谢谢

// get day of month without leading zero
$today = date("j");

//if before 20th get next month, else get two months out
IF ($today < 20) {
    $time =  new DateTime();
    $current_month = $time->modify('+1 months');
}else{  
    $time =  new DateTime();    
    $current_month = $time->modify('+2 months');
}

**//  before January 2022 this worked:  $month =  strtotime($current_month);
//after January 2022 I changed code to this to work
$month = date_format($current_month, 'm');**

    $code = array (
    '01' => 'f',
    '02' => 'g',
    '03' => 'h',
    '04' => 'j',
    '05' => 'k',
    '06' => 'm',
    '07' => 'n',
    '08' => 'q',
    '09' => 'u',
    '10' => 'v',
    '11' => 'x',
    '12' => 'z');

$month_code = $code[$month];

Use **$month = date_format($current_month, 'm');**使用**$month = date_format($current_month, 'm');**

Instead of *$month = strtotime($current_month);*而不是*$month = strtotime($current_month);*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM