我正试图用谷歌事件操纵索姆特定的事情,我可以添加,删除,获取所有事件并在事件上添加颜色,但我有一个问题,每次我插入一个定期事件,我得到的不是有效的时区消息,我不知道如何解决它:/
public void AddRecurringEvents(Calendar service,Event createdEvent, 字符串规则,字符串摘要,字符串位置){
Event event = new Event();
// Define Date Time for each start and end time.
DateTime start = DateTime.parseRfc3339("2014-09-30T10:00:00Z");
DateTime end = DateTime.parseRfc3339("2014-09-30T10:25:00Z");
event.setStart(new EventDateTime().setDateTime(start).setTimeZone(
"Europe/Paris"));
event.setEnd(new EventDateTime().setDateTime(end).setTimeZone(
"Europe/Paris"));
// Setting recurrence
event.setRecurrence(Arrays.asList(rule));
try {
Event recurringEvent = service.events().insert("primary", event)
.execute();
System.out.println(createdEvent.getId());
} catch (IOException e) {
e.printStackTrace();
}
}
任何想法如何解决这个问题?我的代码有问题......
感谢
答案 0 :(得分:1)
尝试这样的事情:
Event event = new Event();
event.setSummary(en.name);
event.setDescription(en.desc);
event.setStatus("confirmed");
ArrayList<String> recurrence = new ArrayList<String>();
recurrence.add("RRULE:FREQ=YEARLY;WKST=MO;");
event.setRecurrence(recurrence);
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(en.year, en.month-1, en.day,0,0,0);
Date startDate = cal.getTime();
Date endDate = new Date(startDate.getTime()); // same Time
DateTime start = new DateTime(startDate, TimeZone.getTimeZone("Europe/Paris"));
event.setStart(new EventDateTime().setDateTime(start).setTimeZone("Europe/Paris"));
DateTime end = new DateTime(endDate, TimeZone.getTimeZone("Europe/Paris"));
event.setEnd(new EventDateTime().setDateTime(end).setTimeZone("Europe/Paris"));
Event createdEvent = client.events().insert( "primary", event).execute();