31 Mar 2018

Correct date value in Android’s CalendarContract.Events

Correct date value in Android’s CalendarContract.Events

Recently I have been running into troubles syncing event date values for custom events in an Android project; I’ve been using the CalendarContract.Events to provide Android’s calendar and events with custom data.

To be more specific, the dates I was trying to put into android were set on EDT (Easter Daylight Time) timezone, and as the documentation is stated, we were updating Android’s date column value DSTART in milliseconds as well as its timezone in column EVENT_TIMEZONE (as America/New_york); but Android was setting the date value to “0 gmt” regardless of the timezone set for the event, meaning that for some reason the timezone difference is not being auto-applied.

The solution was to apply the difference myself prior to updating the value into CalendarContract. To this, I used Android’s Calendar and Timezone classes to fix the date time value, here it is how:

I hope this solutions helps anyone running into the same issue. If you found a different solution, let me know in the comments below.