0
我有一個谷歌icalendar文件。如果我將其導入到我的Mac日曆中,日期爲「DTEND」2017-09-02。這也是對的。 如果我使用php解析的文件會給我日期「DTEND」2017-09-03。 我需要做什麼才能獲得正確的日期?將google icalendar導入到MySQL
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:xxx
X-WR-TIMEZONE:Europe/Berlin
X-WR-CALDESC:xxx
BEGIN:VTIMEZONE
TZID:Etc/UTC
X-LIC-LOCATION:Etc/UTC
BEGIN:STANDARD
TZOFFSETFROM:+0000
TZOFFSETTO:+0000
TZNAME:GMT
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE
BEGIN:VTIMEZONE
TZID:Europe/Berlin
X-LIC-LOCATION:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;VALUE=DATE:20170826
DTEND;VALUE=DATE:20170903
DTSTAMP:20170115T115800Z
UID:7eecd830-1ee2-4c8f-82fb-e4f3283916d6
CLASS:PUBLIC
CREATED:20161204T172327Z
DESCRIPTION:DUMMY
LAST-MODIFIED:20161204T172327Z
LOCATION:
SEQUENCE:1
STATUS:CONFIRMED
SUMMARY:DUMMY
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
的PHP
$ical = new iCalendar();
$ical->parse($filename);
$ical_data = $ical->get_all_data();
$end_dttimearr = explode('T', $data['DTEND']);
$date_end = date_create($end_dttimearr[0]);
$end = date_format($date_end, 'Y-m-d');
感謝您的幫助
iCalendar PHP類從哪裏來的?它不是標準PHP構建的一部分。它有一個bug。你的腳本運行在什麼時區?什麼不只是將PHP時區設置爲$ data ['X-WR-TIMEZONE']? – symcbean