ICS 文件中的错误时间

Wrong time in a ICS file

我正在开发一个 PHP 工具来创建一个将通过邮件发送的 ICS 文件。

创建文件后,我尝试将其添加到 Outlook 2016 或 iCalendar (Apple) 中。除开始时间和结束时间外,所有信息均正确无误。它们偏离一小时。

例子:

BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
PRODID:-//Communication Maker
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTART;TZID=Europe/Zurich:20151201T150000Z
DTEND;TZID=Europe/Zurich:20151201T180000Z
UID:565c50b5ca7d9
LOCATION:Location
SUMMARY:Title
DESCRIPTION:Content
END:VEVENT
END:VCALENDAR

文件信息如下:

开始时间:01/12/2015 @15:00:00

结束时间:01/12/2015 @18:00:00

时区:UTC +01:00 (Europe/Zurich)

这里是 Outlook 和 iCalendar 上的结果:

开始时间:01/12/2015 @16:00:00

结束时间:2015 年 1 月 12 日@19:00:00

我已经搜索了 4 天了,但找不到使用正确数据创建事件的答案。

如果你愿意,我可以给你更多我的代码(HTML 或 PHP Class)。

有我的 class :

class ICS {

    private $sSaveDir        = './icsFiles/';
    private $sIcsContent     = '';
    private $sIcsDateFormat  = 'Ymd\THis\Z';

    public function __construct($sTitle = null, $sLocation = null, $sUrl = null, $sTimezoneValue = null, $sEventText = null, $sDateS = null, $sTimeS = null, $sDateE = null, $sTimeE = null) {

        // Timezone par défaut
        date_default_timezone_set('UTC');

        // Génération de l'ID unique
        $sUniqId = uniqid();

        // Construction du array
        $aIcsContent = array(
            "BEGIN:VCALENDAR",
            "METHOD:PUBLISH",
            "VERSION:2.0",
            "PRODID:-//Communication Maker",
            "CALSCALE:GREGORIAN",
            "BEGIN:VEVENT",
            "DTSTART;TZID=".$sTimezoneValue.":".date($this->sIcsDateFormat, strtotime($sDateS." ".$sTimeS)),
            "DTEND;TZID=".$sTimezoneValue.":".date($this->sIcsDateFormat, strtotime($sDateE." ".$sTimeE)),
            "UID:".$sUniqId,
            "LOCATION:".$sLocation,
            "SUMMARY:".$sTitle,
            "DESCRIPTION:".$sEventText,
            "END:VEVENT",
            "END:VCALENDAR"
        );

        // Array => string
        $this->sIcsContent = implode(PHP_EOL, $aIcsContent);

        // Créer et ouvre le fichier en écriture seule
        if($oIcsFile = fopen($this->sSaveDir.'event_'.$sUniqId.'.ics', 'w')) {

            // Inscrit les données de l'événement dans le fichier
            fwrite($oIcsFile, $this->sIcsContent);

            // Ferme le fichier proprement
            fclose($oIcsFile);

            echo 'true';
        }
        else {

            echo 'false';
        }

    }

}

感谢您的帮助。我真的很需要它。

您的 ICS 文件显示时间是 01/12/2015 @ 15:00:00 UTC 时区。它说要显示苏黎世时间。苏黎世是 UTC+100,因此将时间显示为 01/12/2015 是正确的@16:00:00 苏黎世时间(欧洲中部时间)。

20151201T150000Z 末尾的 Z 表示 "Zulu Time,",这是(大致)UTC 时间的另一个名称。

要使事件开始的 date/time 指定为苏黎世时间,而不是 UTC,只需从时间中删除 Z,如下所示:20151201T150000

如果你想让坐在UTC+100的人看到15:00,让坐在UTC+200的人看到16:00时间,你应该指定UTC时间。在这种情况下,您可以将时间设置为 20151201T140000Z,因为这是 01/12/2015 15:00:00 UTC+100.

的等效 UTC