douyou8047 2015-12-08 15:18
浏览 56

将存储的mysql DateTime从UTC转换为PHP中的本地偏移量

I'm walking into a project where a database is already set up. Up until now, the client has been working with using NOW() in PHP to store a DateTime in mysql. The problem is that now they want people from all over the world to be able to return data and have it display in their current time. So I changed all the functions from NOW() to UTC_TIMESTAMP() so the database is using UTC for all stored DateTime stamps. Looking at the table it's stored as YYYY-MM-DD HH:MM:SS. So how can I can I convert, using PHP, that timestamp from a UTC time to what it would be in their timezone?

So if I'm in GMT-6, and there is a timestamp of "2015-12-08 15:17:20" it'll display as "2015-12-08 09:17:20" on the page?

I've been looking at all sorts of PHP options, I can't really change anything in SQL, nor the database structure, all I can do is take the data being stored and manipulate it with PHP.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?