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 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘