douhao7889 2014-11-07 10:23
浏览 49
已采纳

添加一天时,日期和时间戳在PHP中表现奇怪

I need to add one day to a date using Timestamps. The following code should work but it doesn't :

$date = '2014-10-26';
$date_timestamp = strtotime($date);                // Converting the date to timestamp
$new_date_timestamp = $date_timestamp + 24*60*60;  // Adding one day
$new_date = date("Y-m-d",$new_date_timestamp);     // Formating the new date

It returns $new_date = '2014-10-26' instead of 2014-10-27.

Strangely, it works well for other dates. For example, if $date = '2014-10-28', then it returns $new_date = '2014-10-29', as it should.

I am completely stuck. Any idea to help?

  • 写回答

3条回答 默认 最新

  • doujia9833 2014-11-07 11:38
    关注

    Is the system in England? British Summer Time ended on the 26th at 0100. I think this could account for the discrepancy: during BST, the time is GMT+1. In order to return to GMT, you therefore subtract one hour. 0100 becomes 0000, effectively making 10/26 25 hours long.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部