GetCurrentRealTime

suggest change

This calculates the current time from a trusted reading. Set networkTime and elapsedRealtimeAtSample together when that reading is taken.

private static long networkTime;
private static long elapsedRealtimeAtSample;

public static Calendar getCurrentRealTime() {
    long currentRealTime = networkTime
            + (SystemClock.elapsedRealtime() - elapsedRealtimeAtSample);
    Calendar calInstance = Calendar.getInstance();
    calInstance.setTimeZone(getUTCTimeZone());
    calInstance.setTimeInMillis(currentRealTime);
    return calInstance;
}

Get a UTC timezone.

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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents