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条)

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解