简体   繁体   English

Google Calendar API V3上的重复活动时区无效

[英]Invalid Timezone for Recurring event on Google Calendar API V3

i'm trying to manipulate somme specific things with google events, i can add, delete, get all events and put colors on events, But i Have a problem , each time i ty to insert a recurring event , i get not valid timezone message and i don't know how to fix it :/ 我正在尝试使用Google事件来操纵特定的东西,我可以添加,删除,获取所有事件并在事件上加上颜色,但是我有一个问题,每次我想插入重复事件时,我都收到无效的时区消息而且我不知道如何解决它:/

This my code : 这是我的代码:

public void AddRecurringEvents(Calendar service, Event createdEvent, String rule, String Summary, String Location) { public void AddRecurringEvents(日历服务,事件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();
    }

}

Any ideas how to fix this problem ?? 任何想法如何解决这个问题? is there something wrong with my code ... 我的代码有什么问题吗?

THanks 谢谢

Try something like this: 尝试这样的事情:

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM