简体   繁体   中英

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 :/

This my code :

public void AddRecurringEvents(Calendar service, Event createdEvent, String rule, String Summary, String Location) {

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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