doumou3883 2016-03-28 20:04
浏览 51
已采纳

来自Google日历的.ics导出时间错误

Using PHP,mysql, i am trying to export/import calendar data from/to Google calendar. The importing (to Google) works fine. I can export data from my mysql table and create an ics file then import it into Google Calendar, using a specific timezone.

The problem is when i am exporting the data... Google changes the timezone for every event. I'll give an example.

When i am importing the data to Google Calender, a typical event looks like this:

BEGIN:VEVENT
UID:20
DTSTAMP:20160328T222128
DTSTART:20160328T033000
DTEND:20160328T043000
LOCATION:
DESCRIPTION:My description here
SUMMARY:Event number 3
END:VEVENT

The StartTime is 033000 and EndTime is 043000. Everything is fine, i see an event starting at 3:30am and ending at 4:30am.

When i am exporting my calendar from Google this event looks like this:

BEGIN:VEVENT
DTSTART:20160328T003000Z
DTEND:20160328T013000Z
DTSTAMP:20160328T194501Z
UID:20
CREATED:20160328T224357Z
DESCRIPTION:My description here
LAST-MODIFIED:20160328T194410Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Event number 3
TRANSP:OPAQUE
END:VEVENT

StartTime 003000 EndTime 013000

Both .ics files have X-WR-TIMEZONE:Europe/Athens

Why on earth is Google sending me back Zulu time, instead of what i am seeing in the calendar ? I dont want to handle timezones. This means if a person from the Usa uploads an .ics file to the custom calendar i am making, it will insert wrong times in the database. Is it possible, Google Calendar to export exactly the hours a person sees in his calendar?

If i cant avoid this, what is the easiest way to convert this Z time into the proper time ? (the time that person sees in Google Calendar)

Thanks!

  • 写回答

1条回答 默认 最新

  • douyong4623 2016-03-28 21:42
    关注

    I assume that, since you are able to insert the date/times into a database, you are able to parse the format of DTSTART. If not, I recommend taking a look at sabre/vobject for a full-on iCalendar parser.

    So after parsing DTSTART, make sure you parse this into a php DateTime object. This object makes it really easy to convert to different timezones:

    $dt = new \DateTime($input);
    $dt->setTimeZone(new DateTimeZone('Europe/Athens'));
    

    After that, your $dt contains your start time, converted to your timezone.

    Here's an example with vobject:

    $cal = Sabre\VObject\Reader::read($iCalendarData);
    
    // DTSTART property
    $dtstart = $cal->VEVENT->DTSTART;
    
    // Turn into DateTime object
    $dateTime = $dtstart->getDateTime();
    
    // Convert to your timezone
    $newDateTime = $dateTime->setTimeZone('Europe/Athens');
    

    Disclaimer: I'm the main author for vobject.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备