duanjiwu0324 2013-08-05 07:11
浏览 39
已采纳

时区php Symfony2

I'm using Symfony2 and I'd like to fetch my dates in function to the user timezone. So my dates are stored in a database in the server timezone.

I'd like to convert this date to the user timezone before fetching and set the date to the server timezone before saving it into my database.

I'm using Datetime

Thanks or your help

  • 写回答

1条回答 默认 最新

  • douqiao2471 2013-08-05 08:22
    关注

    Try somethink like this :

    $userTimezone = new DateTimeZone('America/New_York');
    $serverDateTime = new DateTime('2013-08-05 10:10');
    $offset = $userTimezone->getOffset($serverDateTime);
    echo $offset;
    

    Now with the offset you should be able to modify the date like this :

    $serverDateTime->modify('+'.$offset.' seconds');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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