GetCurrentRealTime

這計算當前裝置時間並加上/減去實際和裝置時間之間的差異

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;
}

獲取基於 UTC 的時區。

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