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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分