duangongqiong6958 2013-08-20 12:59
浏览 149
已采纳

时间戳,时区和夏令时

I've got quite a large central MySQL database. Up till now, I've been using unix timestamps to store dates / times.

This all worked fine up until a few months back, when all of a sudden lots of data which is retrieved from the database went missing. I checked the database, and it was all there, unaltered.

The applications I created are precise down to the second, and when daylights savings took over, it through my application off by 3599 seconds (3600 seconds in an hour)

I'm trying to get my head around timezones / daylights savings etc and struggling to understand the concepts slightly!!

All my PHP files are set to the Europe/London timezone. All dates, times etc in my database are stored as unix timestamps (integers).

Should I convert all the timestamps to the datetime() field type? Or is there a way to avoid daylights savings? If I switch to UTC, will I need to adjust any of the timestamps?

Any advice is greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dqdt45183 2013-08-20 13:09
    关注

    You can keep your unix timestamps in your database unaltered.

    It is your application which is changing the retrieved times to server time, Europe/London in your case, which implements DST as you are aware.

    Set your server to UTC and start using the DateTime classes to avoid these problems in the future.

    Also make sure to set your default timezone to UTC in php.ini

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题