strtotime未能及时增加30天

我的代码是:


$result = 20201601; //fetched from a source as string


//Convert string to date format 'Y/m/d'


$date1 = substr($result, 0, 4) . '/' . substr($result, 4, 2) . '/' . substr($result, 6, 2); 


echo $date1 . "<br>";


//Add 30 days to it


$date2 = date('Y/m/d', strtotime('+30 days', strtotime($date1)));


echo $date2;


if ($date2 < date('Y/m/d', strtotime('now')))

{

    //If date fetched ($result) is older than 30 days from today's date, then fetch new date from source

}

代码无法在以下位置添加 30 天:,它给出:date('Y/m/d', strtotime('+30 days', strtotime($date1)))1970/01/30



噜噜哒
浏览 102回答 1
1回答

一只萌萌小番薯

改变$date1&nbsp;=&nbsp;substr($result,&nbsp;0,&nbsp;4)&nbsp;.&nbsp;'/'&nbsp;.&nbsp;substr($result,&nbsp;4,&nbsp;2)&nbsp;.&nbsp;'/'&nbsp;.&nbsp;substr($result,&nbsp;6,&nbsp;2);自$date1&nbsp;=&nbsp;substr($result,&nbsp;0,&nbsp;4)&nbsp;.&nbsp;'/'&nbsp;.&nbsp;substr($result,&nbsp;6,&nbsp;2)&nbsp;.&nbsp;'/'&nbsp;.&nbsp;substr($result,&nbsp;4,&nbsp;2);这是必需的,因为您当前的数据的格式为 。一个月不能有值。2020160116
打开App,查看更多内容
随时随地看视频慕课网APP