简体   繁体   English

读取Ical(.ics)文件会给我错误的时间。 我想念什么?

[英]Reading an Ical(.ics) file gives me wrong times. What am i missing?

I am getting wrong values reading from an.ics file(ical format). 我从an.ics文件(标准格式)中读取了错误的值。 I suspect my timezone is not setup properly. 我怀疑我的时区设置不正确。

This is one sample: 这是一个示例:

BEGIN:VCALENDAR
PRODID:-//Ben Fortuna//iCal4j 1.0//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20140625T024631Z
DTSTART:20140623T060000Z
DTEND:20140623T065000Z
UID:492532-7692-c75853
SUMMARY:4A RK R4A
LOCATION:Tolk

As you can see it says on DTSTART, that the event beginns at 060000Z which is at 6 in the mornig. 正如您在DTSTART上看到的那样,该事件开始于060000Z,该位置在mornig中的6。 But i got the ical file from a shool timetable where the first class beginns at 08:00 in the morning. 但是我从学校时间表那里得到了文件,那里的第一堂课是在早上08:00开始的。

So i am confused what the reason for this is. 所以我很困惑这是什么原因。 This is where I got the ical file from: enter link description here 这是我从此处获得ical文件的地方: 在此处输入链接描述

Any help would be greatly appreciated. 任何帮助将不胜感激。

You need to correct for the timezone. 您需要更正时区。 The times in the .ics file are in the UTC timezone and that site is in Germany (CET timezone) so 6am UTC is actually 8am CEST. .ics文件中的时间位于UTC时区,而该站点位于德国(CET时区),因此UTC上午6点实际上是CEST上午8点。

For example: 例如:

<?php
//Create DateTime object of .ics time in UTC timezone
$utcTz = new DateTimeZone('UTC');
$dateTime = new DateTime('20140623T060000Z', $utcTz);

echo $dateTime->format("Y-m-d H:i:s"); //2014-06-23 06:00:00

//Change to CET timezone
$cetTz = new DateTimeZone('Europe/Berlin');
$dateTime->setTimezone($cetTz);

echo $dateTime->format("Y-m-d H:i:s"); //2014-06-23 08:00:00

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM