GetCurrentRealTime
suggest changeThis 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");
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents