我的将日期添加一天的代码返回添加日期之前的日期: 2009-09-30 20:24:00添加一天之后的日期应滚动到下个月:1970-01-01 17:33:29
2009-09-30 20:24:00
1970-01-01 17:33:29
<?php //add day to date test for month roll over $stop_date = date('Y-m-d H:i:s', strtotime("2009-09-30 20:24:00")); echo 'date before day adding: '.$stop_date; $stop_date = date('Y-m-d H:i:s', strtotime('+1 day', $stop_date)); echo ' date after adding one day. SHOULD be rolled over to the next month: '.$stop_date; ?>
我以前使用过非常相似的代码,我在这里做错了什么?
<?php $stop_date = '2009-09-30 20:24:00'; echo 'date before day adding: ' . $stop_date; $stop_date = date('Y-m-d H:i:s', strtotime($stop_date . ' +1 day')); echo 'date after adding 1 day: ' . $stop_date; ?>
对于PHP 5.2.0+,您还可以执行以下操作:
$stop_date = new DateTime('2009-09-30 20:24:00'); echo 'date before day adding: ' . $stop_date->format('Y-m-d H:i:s'); $stop_date->modify('+1 day'); echo 'date after adding 1 day: ' . $stop_date->format('Y-m-d H:i:s');