Google Calendar API:事件结束时间减少了1天 [英] Google Calendar API: Event endTime is decremented by 1 day

查看:76
本文介绍了Google Calendar API:事件结束时间减少了1天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在自己的Java类中使用Google Calendar API.不幸的是,新创建的事件的endTime(在这种情况下是休假)似乎减少了1天.

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.

示例:我使用startTime 2011-01-01和endTime 2011-01-05创建一个事件,该事件将显示在2011年1月1日至2011年1月4日之间的Google日历中.

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)

推荐答案

如果您没有为 DateTime.parseDate()提供时间,则默认为午夜.从1号午夜开始到5号午夜结束的事件将在第一天到第四天作为全天事件运行在界面中.该时间段不包含任何在5号的时间,因此不会显示为5号.

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.

您需要将结束时间设置为2011-01-05 23:59,或者将结束日期添加一天.

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

这篇关于Google Calendar API:事件结束时间减少了1天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆