douhao7889 2014-11-07 18: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 19: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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!