Wrong time in a ICS file

試著忘記壹切 提交于 2021-01-29 07:31:59

问题


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

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.

Exemle :

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

Here are the file informations :

Start time : 01/12/2015 @ 15:00:00

End time : 01/12/2015 @ 18:00:00

Timezone : UTC +01:00 (Europe/Zurich)

And here, the results on Outlook and iCalendar :

Start time : 01/12/2015 @ 16:00:00

End time : 01/12/2015 @ 19:00:00

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

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

There is my 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';
        }

    }

}

Thank you for your help. I really need it.


回答1:


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).

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

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

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.



来源:https://stackoverflow.com/questions/34000110/wrong-time-in-a-ics-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!