亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

strtotime 未能及時添??加 30 天

strtotime 未能及時添??加 30 天

PHP
慕工程0101907 2022-07-22 18:47:51
我的代碼是:$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
查看完整描述

1 回答

?
翻閱古今

TA貢獻1780條經驗 獲得超5個贊

改變

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

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

這是必需的,因為您當前的數據是 format 20201601。一個月不能有值16


查看完整回答
反對 回復 2022-07-22
  • 1 回答
  • 0 關注
  • 107 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號