dongmu2517 2011-06-22 06:49
浏览 27
已采纳

GMT转换问题的另一个日期时间

I am pulling a feed from Google Calendar. It has the event start time in this format:

StartDate: 2011-06-25T18:00:00.000-05:00

I understand that the -05:00 is the timezone offset. I need the above to get put into the mySQL database in GMT time. I was just reading about date() and gmdate() but I'm afraid I'm pretty new at this and I don't seem to be getting the results I need.

Right now the above code ends up being this in my datetime colum in mySQL:

2011-06-25 18:00:00

I need the above to be:

2011-06-25 23:00:00

But I need a dynamic way to do this so any user with a different timezone will get the correct results-IE: I need the function to be smart enough to read the timezone offset and make the needed changes regardless of the offset. I'm hoping there is a PHP function that does this already?

Thanks for any help!

  • 写回答

3条回答 默认 最新

  • dongyinju5977 2011-06-22 06:56
    关注

    If you use strtotime, you can do this:

    <?
    date_default_timezone_set('UTC');
    $date = strtotime('2011-06-25T18:00:00.000-05:00');
    echo date('Y-m-d H:i:s',$date);
    

    This results on my system in:

    2011-06-25 23:00:00
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程