doudeng5764 2014-04-14 09:20
浏览 24
已采纳

时区和夏季时间在不同的州

I have a problem with PHP IMAP timezones.

I have a server that download emails from my users accounts. And than the users can view their email on my website.

I set the php timezone of my server to UTC 0 and now i want that my users see the receiving time of the emails to their timezones. But the problem is the summer time because the timezone change of 1 hour.

Example:

GMail give me an email with received time in UTC (0) at 7:00.

In Italy, the timezone is UTC +1 so i can add 1 hour to this time, then it will be 8:00.

But now in Italy we have the summer timezone so the UTC must be +2 not +1 but not all countries have this. So i ask if exists maybe a online service that can give me the correct offset that i must add to the hour for showing the correct time.

Thank you in advance.

  • 写回答

1条回答 默认 最新

  • dqch34769 2014-04-14 09:31
    关注

    In Italy the time zone swaps between CET and CEST so you cannot hard-code it using names that do not reflect this fact. You need to use geographical identifiers like Europe/Rome:

    <?php
    
    $utc = new DateTimeZone('UTC');
    $rome = new DateTimeZone('Europe/Rome');
    
    $winter = new DateTime('2013-12-31', $utc);
    $summer = new DateTime('2013-08-31', $utc);
    
    $winter->setTimezone($rome);
    $summer->setTimezone($rome);
    
    echo $winter->format('r') . PHP_EOL;
    echo $summer->format('r') . PHP_EOL;
    
    Tue, 31 Dec 2013 01:00:00 +0100
    Sat, 31 Aug 2013 02:00:00 +0200
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3