Chapter 18. Time
Telling Time and Dates
Representing Time
Unix and Linux keep track of time in seconds before or after the epoch, which is defined as midnight, January 1, 1970 UTC.[1] Positive time values are after the epoch; negative time values are before the epoch. In order to provide processes with the current time, Linux, like all versions of Unix, provides a system call called time()
:
#include <time.h> time_t time(time_t *t);
time()
returns the number of seconds since the epoch, and if t
is non-null, it also fills in t
with the number of seconds since the epoch.
Some problems require higher resolution. Linux provides another system call, gettimeofday()
, which provides more information:
#include <sys/time.h> #include <unistd.h> int gettimeofday(struct ...
Get Linux Application Development, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.