How can I get the absolute system boot time within the shell? i tried cat/proc/uptime, but this only returns the time since reboot.
Asked
Active
Viewed 1.8k times
11
-
how is that different ? – njzk2 Mar 11 '13 at 15:24
-
absolute time is the timestamp when the system booted. I want to know this. But uptime just returns the timespan since reboot. – Similitran Mar 11 '13 at 15:30
-
14So substract. Current time - uptime. Any boot, be it reboot counts as a fresh boot for most OSes since they're the ones that have been restarted and they keep track of uptime. – A--C Mar 11 '13 at 15:31
-
1@A--C put that in as answer :) – Warpzit Mar 27 '13 at 14:42
1 Answers
20
It's basically:
java.lang.System.currentTimeMillis() - android.os.SystemClock.elapsedRealtime();

flx
- 14,146
- 11
- 55
- 70
-
-
7
-
take into account that the user could change the time and currentTimeMillis() wont be correct, you should fix that by listening to ACTION_TIME_CHANGED http://developer.android.com/reference/android/content/Intent.html#ACTION_TIME_CHANGED – Chiara Dec 18 '14 at 12:37
-
1System.currentTimeMillis() is not affected by timezone, it returns UTC timestamp. – Kurovsky Feb 10 '17 at 08:35
-
-
That's right. "elapsedRealtimeNanos return the time since the system was booted, and include deep sleep. This clock is guaranteed to be monotonic, and continues to tick even when the CPU is in power saving modes, so is the recommend basis for general purpose interval timing." – Zhou Hongbo Sep 23 '19 at 07:48
-
Case1: user changes time from settings according to @keen; Case2: the `System.currentTimeMills()` is not current real time because the stupid rom, I have a device that the system time begin from a specific value every time reboot the system. – DysaniazzZ Oct 28 '19 at 02:57
-
java.lang.System.currentTimeMillis() changes when changing the system clock from settings. so the result could be incorrect in this case. – Mahmoud Jan 31 '20 at 07:50