Since the date stored in the database is already in UTC, you can just use the value right away. Or the alternative way is to get a Calendar
instance and set the time in milliseconds using setTimeInMillis(long millis)
.
For the current date & time on the device, invoking Calendar.getInstance()
will return a Calendar
with device's time zone, date and time.
The getTimeInMillis()
will return the UTC milliseconds from epoch, which is independent of the time zone.
Try
long dbMillis = ... // get date value from DB, in UTC already
Calendar cal = Calendar.getInstance(); // get device's date time with
// default device time zone
long now = cal.getTimeInMillis(); // returns device's date time in UTC
long diff = Math.abs(now - dbMillis);