Skip to Main Content
Linux Application Development, Second Edition
book

Linux Application Development, Second Edition

by Michael K. Johnson, Erik W. Troan
November 2004
Intermediate to advanced content levelIntermediate to advanced
736 pages
14h 4m
English
Addison-Wesley Professional
Content preview from Linux Application Development, Second Edition

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux System Programming, 2nd Edition

Linux System Programming, 2nd Edition

Robert Love

Publisher Resources

ISBN: 0321219147Purchase book