为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 127 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号