开发者

Google Calendar API: Event endTime is decremented by 1 day

开发者 https://www.devze.com 2023-02-02 16:45 出处:网络
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.

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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号