gettimeofday, settimeofday - get or set the date and time
int gettimeofday(struct timeval *tp, void *);
int settimeofday(struct timeval *tp, void *);
The gettimeofday() function gets and the settimeofday()
function sets the system's notion of the current time. The
current time is expressed in elapsed seconds and
microseconds since 00:00 Universal Coordinated Time, January
1, 1970. The resolution of the system clock is hardware
dependent; the time may be updated continuously or in clock
The tp argument points to a timeval structure, which
includes the following members:
long tv_sec; /* seconds since Jan. 1, 1970 */
long tv_usec; /* and microseconds */
If tp is a null pointer, the current time information is not
returned or set.
The TZ environment variable holds time zone information. See
The second argument to gettimeofday() and settimeofday() is
Only the super-user may set the time of day.
Upon successful completion, 0 is returned. Otherwise, -1 is
returned and errno is set to indicate the error.
The gettimeofday() function will fail if:
The structure pointed to by tp specifies an invalid
EPERM A user other than the privileged user attempted to set
the time or time zone.
Additionally, the gettimeofday() function will fail for 32-
bit interfaces if:
The system time has progressed beyond 2038, thus the
size of the tv_sec member of the timeval structure
pointed to by tp is insufficient to hold the current
time in seconds.
If the tv_usec member of tp is > 500000, settimeofday()
rounds the seconds upward. If the time needs to be set with
better than one second accuracy, call settimeofday() for the
seconds and then adjtime(2) for finer accuracy.
See attributes(5) for descriptions of the following attri-
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
| MT-Level | MT-Safe |
adjtime(2), ctime(3C), TIMEZONE(4), attributes(5)
Man(1) output converted with