How can I get system time from a proc file? I know we can get system time from some commands such as date, and also can write some code based on time API. But I really need to use a simple proc file to get the time. No matter what the time format is, a simple value is OK. For example, the total seconds from 1970/1/1 is really good enough.
Asked
Active
Viewed 5,902 times
3
-
2First you need to modify the proc filesystem to include this information. – Ignacio Vazquez-Abrams Mar 09 '11 at 06:48
-
1Care to explain *why* you need it specifically from proc file? Maybe there is some other way that would serve the ultimate goal. – Jan Hudec Mar 09 '11 at 08:04
2 Answers
15
Yes, you can :
cat /proc/driver/rtc
From man:
RTC vs system clock
RTCs should not be confused with the system clock, which is a
software clock maintained by the kernel and used to implement
gettimeofday(2) and time(2), as well as setting timestamps on files,
and so on. The system clock reports seconds and microseconds since a
start point, defined to be the POSIX Epoch: 1970-01-01 00:00:00 +0000
(UTC).
More here

Vladimir Panteleev
- 24,651
- 6
- 70
- 114
-
1Does /proc/driver/rtc always show the time in UTC? It does on my laptop (Ubuntu 14.04) although my system time (as shown by /bin/date) is in BST (UTC+1) – Kaoru Jun 22 '14 at 08:17
1
You can get the amount of time since the system booted from /proc/uptime
, but there is no way I know of to get the real time from /proc
.

jchl
- 6,332
- 4
- 27
- 51