Android GetCurrentRealTime


Example

This calculate current device time and add/subtract difference between real and device time

public static Calendar getCurrentRealTime() {

    long bootTime = networkTime - SystemClock.elapsedRealtime();
    Calendar calInstance = Calendar.getInstance();
    calInstance.setTimeZone(getUTCTimeZone());
    long currentDeviceTime = bootTime + SystemClock.elapsedRealtime();
    calInstance.setTimeInMillis(currentDeviceTime);
    return calInstance;
}

get UTC based timezone.

public static TimeZone getUTCTimeZone() {
    return TimeZone.getTimeZone("GMT");
}