3

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.

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
flypen
  • 2,515
  • 4
  • 34
  • 51

2 Answers2

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
  • 1
    Does /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