Google Calendar API: Event endTime is decremented by 1 day

旧时模样 提交于 2021-02-08 03:29:06

问题


I'm trying to use the Google Calendar API in my own Java class. Unfortunately, the endTime of the newly created event (vacation in this case) seems to decremented by 1 day.

Example: I create an event with startTime 2011-01-01 and endTime 2011-01-05 the event will show up in Google Calendar from 2011-01-01 to 2011-01-04.

This is what I got so far (just the date part, taken from the Google Calendar API Developer's Guide, changed to Date because I want All Day events):

...
CalendarEventEntry myEntry = new CalendarEventEntry();

DateTime startTime = DateTime.parseDate("2011-01-01");  
DateTime endTime = DateTime.parseDate("2011-01-05");

When eventTimes = new When();
eventTimes.setStartTime(startTime);
eventTimes.setEndTime(endTime);
myEntry.addTime(eventTimes);

Reminder reminder = new Reminder();
reminder.setMethod(Method.NONE);
myEntry.getReminder().add(reminder);

CalendarEventEntry insertedEntry = myService.insert(postUrl, myEntry);
...

Could this be somehow related to timezone issues? (I am from Germany)


回答1:


When you don't provide DateTime.parseDate() with a time it will default to midnight. An event starting at midnight on the 1st and ending midnight on the 5th will display in the interface as running as full-day events from the 1st to the 4th. The time period doesn't include any time on the 5th, so it won't be displayed as being on the 5th.

You either need to set the end time as 2011-01-05 23:59, or add a day to the end date.



来源:https://stackoverflow.com/questions/4578550/google-calendar-api-event-endtime-is-decremented-by-1-day

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!