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 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧