DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

gettimeofday(2)


gettimeofday, settimeofday -- date and time functions

Synopsis

   #include <sys/time.h>
   

int gettimeofday(struct timeval *tp, void *reserved);

int settimeofday(struct timeval *tp, void *reserved);

Description

gettimeofday gets and settimeofday 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 ticks.

tp 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 second argument to these functions, reserved, should be NULL.

The TZ environment variable holds time zone information. See timezone.

The calling process must have the P_SYSOPS privilege to set the time of day.

Return values

A -1 return value indicates that an error occurred and errno has been set.

Errors

The following error codes may be set in errno:


EINVAL
tp specifies an invalid time.

EPERM
An attempt was made to set the time of day and the caller did not have the P_SYSOPS privilege.

References

adjtime(2), ctime(3C), time(2), timezone(4)

Notices

The implementation of settimeofday ignores the tv_usec field of tp. If the time needs to be set with better than one second accuracy, call settimeofday for the seconds and then adjtime for finer accuracy.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004