【问题标题】:Reading an Ical(.ics) file gives me wrong times. What am i missing?读取 Ical(.ics) 文件给了我错误的时间。我错过了什么?
【发布时间】:2014-08-16 12:45:27
【问题描述】:

我从 an.ics 文件(ical 格式)读取的值有误。我怀疑我的时区设置不正确。

这是一个示例:

BEGIN:VCALENDAR
PRODID:-//Ben Fortuna//iCal4j 1.0//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20140625T024631Z
DTSTART:20140623T060000Z
DTEND:20140623T065000Z
UID:492532-7692-c75853
SUMMARY:4A RK R4A
LOCATION:Tolk

正如您在 DTSTART 上看到的那样,事件开始于 060000Z,也就是早上 6 点。但是我从早上 08:00 开始第一堂课的学校时间表中获得了 ical 文件。

所以我很困惑这是什么原因。 这是我从以下获得 ical 文件的地方: enter link description here

任何帮助将不胜感激。

【问题讨论】:

    标签: php date timezone icalendar


    【解决方案1】:

    您需要更正时区。 .ics 文件中的时间位于 UTC 时区,而该站点位于德国(CET 时区),因此 UTC 上午 6 点实际上是 CEST 上午 8 点。

    例如:

    <?php
    //Create DateTime object of .ics time in UTC timezone
    $utcTz = new DateTimeZone('UTC');
    $dateTime = new DateTime('20140623T060000Z', $utcTz);
    
    echo $dateTime->format("Y-m-d H:i:s"); //2014-06-23 06:00:00
    
    //Change to CET timezone
    $cetTz = new DateTimeZone('Europe/Berlin');
    $dateTime->setTimezone($cetTz);
    
    echo $dateTime->format("Y-m-d H:i:s"); //2014-06-23 08:00:00
    

    【讨论】:

    • @user3668120:用一个例子更新了我的答案。
    猜你喜欢
    • 2019-08-29
    • 2015-10-06
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 2013-08-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    相关资源
    最近更新 更多