ICS文件中的时间错误 [英] Wrong time in a ICS file

查看:55
本文介绍了ICS文件中的时间错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I 'm developing a PHP tool to create an ICS file that will be sent by mail.

创建文件后,我尝试将其添加到Outlook 2016或iCalendar(Apple)中.除开始时间和结束时间外,所有信息都是正确的.它们从一小时开始偏移.

After creating the file, I try to add it in Outlook 2016 or iCalendar (Apple) . All information is correct except the start time and end time. They are offset from one hour.

示例:

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

以下是文件信息:

开始时间:2015年1月12日@ 15:00:00

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

时区:UTC +01:00(欧洲/苏黎世)

在这里,Outlook和iCalendar上的结果:

And here, the results on Outlook and iCalendar :

开始时间:2015年1月12日@ 16:00:00

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

我已经搜索了4天,但找不到正确数据进行活动的答案.

I have searched for 4 days now and I can't find the answer to make an event with correct data.

如果您愿意,我可以给您更多我的代码(HTML或PHP类).

I can give you more of my code (HTML or PHP Class) if you want.

有我的课:

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';
        }

    }

}

感谢您的帮助.我真的很需要.

Thank you for your help. I really need it.

推荐答案

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

Your ICS file says that the time is 01/12/2015 @ 15:00:00 UTC time zone. It says to display the time in Zurich time. Zurich is UTC+100 so it is correct to show the time as 01/12/2015 @ 16:00:00 Zurich time (Central European Time).

20151201T150000Z 末尾的 Z 表示祖鲁时间",(大约)是UTC时间的另一个名称.

The Z at the end of 20151201T150000Z means "Zulu Time," which is (roughly) another name for UTC time.

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

To make the date/time for the event to start be specified in Zurich time, rather than UTC, simply drop the Z from the time, like this: 20151201T150000

如果您希望让坐在UTC + 100的人看到15:00,而让坐在UTC + 200的人看到16:00,您应该以UTC指定时间.在这种情况下,您可以将时间设置为 20151201T140000Z ,因为这是2015年12月12日15:00:00 UTC + 100的UTC等效时间.

If you want the person sitting in UTC+100 to see 15:00, and the person sitting in UTC+200 to see 16:00 as the time, you should specify the time in UTC. In this case, you would set the time to 20151201T140000Z, since that is the UTC equivalent for 01/12/2015 15:00:00 UTC+100.

这篇关于ICS文件中的时间错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆