Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm creating an ics file with PHP like this:

<?php
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=event.ics');
?>

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//My company//My name//DE
METHOD:PUBLISH
BEGIN:VEVENT
UID:<?php echo base64_encode(random_bytes(64))."
";?>
LOCATION:At my house
SUMMARY:Meeting
DESCRIPTION:Important meeting
CLASS:PUBLIC
DTSTART:20210201T100000Z
DTEND:20210201T150000Z
END:VEVENT
END:VCALENDAR

The event starts at 10 o'clock and ends at 15 o'clock German time, as specified in the ics file. I'm located in Germany and I want to use the German time zone.

After downloading, I imported this in the Calendar app on my Mac. Unfortunately, the event gets created with starting at 11 o'clock and ending at 16 o'clock, instead of 10 o'clock and 15 o'clock, as specified in the ics file.

I think there's something wrong with the time zone. How can I set the right zone? What's the proper way to so that?

question from:https://stackoverflow.com/questions/65869896/wrong-time-timezone-when-creating-ics-file-with-php

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

Your times are entered as UTC time and are displayed as local time after the download. If local times are given, you must convert them to UTC time for the ICS entry.. You can use gmdate() for this, for example.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...