在php中添加六个月
发布时间:2020-12-13 13:45:01 所属栏目:PHP教程 来源:网络整理
导读:我试图从当前日期开始的六个月. 我尝试过使用: 日期(‘d’,strtotime(‘6个月’,时间())); 但它似乎不起作用,总是返回01.有没有更好的方法来做到这一点? 谢谢! 我觉得使用 DateTime更容易使用: $datetime = new DateTime();$datetime-modify('+6 months'
我试图从当前日期开始的六个月.
我尝试过使用: 日期(‘d’,strtotime(‘6个月’,时间())); 但它似乎不起作用,总是返回01.有没有更好的方法来做到这一点? 谢谢!
我觉得使用
DateTime更容易使用:
$datetime = new DateTime(); $datetime->modify('+6 months'); echo $datetime->format('d'); 要么 $datetime = new DateTime(); $datetime->add(new DateInterval('P6M')); echo $datetime->format('d'); 或者在PHP 5.4版中 echo (new DateTime())->add(new DateInterval('P6M'))->format('d'); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |