当我尝试使用下面的代码创建事件时,它将事件添加到日历中,但是直到我通过Google Calendar app
重新加载日历后,它才真正显示具有UTC时区的事件:
ContentResolver cr = context.getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.ALL_DAY, true);
values.put(CalendarContract.Events.DTSTART, startTime); //UTC LONG
values.put(CalendarContract.Events.DTEND, endTime + DateUtils.DAY_IN_MILLIS); // UTC Long
values.put(CalendarContract.Events.EVENT_TIMEZONE, Time.TIMEZONE_UTC);
values.put(CalendarContract.Events.TITLE, title);
values.put(CalendarContract.Events.EVENT_LOCATION, loc);
values.put(CalendarContract.Events.DESCRIPTION, desc);
values.put(CalendarContract.Events.CALENDAR_ID, Long.parseLong(calendarId));
values.put(CalendarContract.Events.EVENT_COLOR, color);
values.put(CalendarContract.Events.HAS_ALARM, true);
values.put(CalendarContract.Events.HAS_ATTENDEE_DATA, true);
cr.insert(CalendarContract.Events.CONTENT_URI.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, acc)
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, typ)
.build(), values);
以下是当地时区为伦敦的事件的输出:
**Created By GC App:**
TITLE: by gc app,
START_DAY: 2458378,
END_DAY: 2458380,
START_MINUTE: 0,
END_MINUTE: 1440,
EVENT_TIMEZONE: UTC,
START: 1537056000000,
END: 1537315200000
**Created By CalendarContract code:**
TITLE: by calendarcontract,
START_DAY: 2458378,
END_DAY: 2458381, // different end day
START_MINUTE: 60, // different start minute
END_MINUTE: 60, // different end minute
EVENT_TIMEZONE: UTC,
START: 1537056000000, // same start time
END: 1537315200000 // same end time
但是当我通过Google calendar app
更改设备时区或刷新日历时,它开始正确显示。