O'Reilly logo

Linux Application Development, Second Edition by Erik W. Troan, Michael K. Johnson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required