This section describes the
time_t data type for representing calendar
time as simple time, and the functions which operate on simple time objects.
These facilities are declared in the header file time.h.
This is the data type used to represent simple time. Sometimes, it also represents an elapsed time. When interpreted as a calendar time value, it represents the number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time. (This calendar time is sometimes referred to as the epoch.) POSIX requires that this count not include leap seconds, but on some systems this count includes leap seconds if you set
TZto certain values (see TZ Variable).
Note that a simple time has no concept of local time zone. Calendar Time T is the same instant in time regardless of where on the globe the computer is.
In the GNU C library,
time_tis equivalent to
long int. In other systems,
time_tmight be either an integer or floating-point type.
difftime tells you the elapsed time between two
simple calendar times, which is not always as easy to compute as just
subtracting. See Elapsed Time.
timefunction returns the current calendar time as a value of type
time_t. If the argument result is not a null pointer, the calendar time value is also stored in
*result. If the current calendar time is not available, the value
stimesets the system clock, i.e. it tells the system that the current calendar time is newtime, where
newtimeis interpreted as described in the above definition of
settimeofdayis a newer function which sets the system clock to better than one second precision.
settimeofdayis generally a better choice than
stime. See High-Resolution Calendar.
Only the superuser can set the system clock.
If the function succeeds, the return value is zero. Otherwise, it is
errnois set accordingly:
- The process is not superuser.