dpq39825 2017-03-17 09:17
浏览 126

PHP Unix时间戳在一天内转换一小时

I'm working on an existing website which uses Unix timestamps for saving date/time information (as an INT UNSIGNED column in MySQL).

If a user enters a date of 26th March 2017 with any time (the start of British Summer Time, when UK clocks go forward by an hour), when this is saved to the database and then extracted and displayed using date, the time shown is one hour greater than that entered by the user. For example, 2017-03-26 20:00:00 when saved becomes 2017-03-26 21:00:00 when displayed. However, this only happens for 26th March 2017 - dates before and after show the same time as entered by the user.

I could understand if this was happening for every day after 26th March but I have no idea why it would only happen on one day. The site didn't have this problem last year either at the beginning or end of British Summer Time.

The default timezone is set to Europe/London (using date_default_timezone_set('Europe/London');) in a file which is included on every page and phpinfo also shows Europe/London as the default timezone.

The server time is correct and the date command gives me: Fri 17 Mar 08:55:13 GMT 2017.

The server has recently been upgraded which resulted in a version bump from PHP 5.3.x to 5.6.x so that is the only thing I can think of which may have caused this issue.

Is there anything I can do to resolve this, apart from using DATETIME fields (a longer term goal, but not something that can be done in a few days) or subtracting 3600 seconds from timestamps if their date is 26/03/2017 (gets very messy and there are too many places where timestamps are used for that to be practical).

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看