dongxian7194 2015-03-21 17:31 采纳率: 0%
浏览 308
已采纳

使用PHP自动将UTC转换为本地时间

Im using MySQL with PHP, and the project is a kind of notification manager

if some one does some thing, a new notification need to be posted in the common post-ground

the issue is - we have users from multiple timezones, currently Im using "datetime" as the field type, so what ever I enter converts into UTC

for example: Im from India(+5:30) and if I create a notification at 21/3/2015 22:50:00, it is saving in DB as 21/3/2015 17:20:00

storing works perfectly well from all zones, but while retrieving it shows for me as 21/3/2015 17:20:00(UTC) but Im expecting in my timezone(IST +5:30) so what Im expecting is 21/3/2015 22:50:00.

is there a way to mention in the query itself to get the time converted in the fetching itself?

or any other way to convert and process further?

any help on this is greatly appreciated.

Thank you

  • 写回答

2条回答 默认 最新

  • duanmo6937 2015-03-21 17:39
    关注

    You can use the function convert_tz so while selecting you can use the following

    mysql> select convert_tz('2015-03-21 17:20:00','+00:00','+05:30') as ist_time;
    +---------------------+
    | ist_time            |
    +---------------------+
    | 2015-03-21 22:50:00 |
    +---------------------+
    1 row in set (0.00 sec)
    

    All you need to do is to change the hard coded date '2015-03-21 17:20:00' to your column name in the selection.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题