Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

outlook - Wrong time (timezone) when creating ics file with PHP

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...