androiddatedatetimejava-calendar

Set android alarm in UTC


I'm using an API to fetch movie releases for my Android app and the release dates are in milliseconds UTC. When I take that release date and set it on the user's phone it gets converted in his time zone and called.

Example:

A movie's release date in milliseconds:

1509667200000

To UTC time & date:

Fri Nov 03 2017 00:00:00

To local time & date: (Eastern time, my timezone)

Thu Nov 02 2017 20:00:00

When I set my alarm

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(releaseDate);
    Date date = calendar.getTime();
    alarmManager.set(AlarmManager.RTC_WAKEUP, date.getTime(), alarmIntent);

Solution

  • What I did and now it works perfectly:

        // Calendar
        TimeZone timeZone = TimeZone.getTimeZone("UTC");
        Calendar calendar = Calendar.getInstance(timeZone);
        calendar.setTimeInMillis(releaseDate);
        Date date = calendar.getTime();
        alarmManager.set(AlarmManager.RTC_WAKEUP, date.getTime(), alarmIntent);