gettimeofday(2) CLIX gettimeofday(2)
NAME
gettimeofday - Gets date and time
LIBRARY
Berkeley Software Distribution Library (libbsd.a)
SYNOPSIS
#include <sys/time.h>
int gettimeofday(
struct timeval *tp ,
struct timezone *tzp );
PARAMETERS
tp Points to a structure in which the elapsed time since the Epoch (Jan
1, 1970) is returned.
tzp Points to a structure in which timezone information for this system
is returned.
DESCRIPTION
The system's definition of the current Greenwich Mean Time (GMT) and the
current time zone is obtained with the gettimeofday() call. The time is
expressed in seconds and microseconds since the Epoch (00:00:00 January 1,
1970). The resolution of the system clock is hardware-dependent, and the
time may be updated continuously or in ``ticks''. If tzp is 0, the time
zone information will not be returned or set.
The structures pointed to by tp and tzp are defined in <sys/time.h> as
follows:
struct timeval {
long tv_sec; /* seconds since Jan. 1, 1970 */
long tv_usec; /* and microseconds */
};
struct timezone {
int tz_minuteswest; /* Minutes west of Greenwich */
int tz_dsttime; /* type of dst correction to apply */
};
The timezone structure indicates the local time zone (measured in minutes
of time westward from Greenwich), and a flag that, if nonzero, indicates
that daylight savings time applies locally during the appropriate part of
the year.
2/94 - Intergraph Corporation 1
gettimeofday(2) CLIX gettimeofday(2)
EXAMPLES
To get the current date and time:
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
NOTES
Microsecond granularity is not available. Therefore, the tv_usec field of
the timeval structure will be set based on 1/60 second intervals.
RETURN VALUES
Upon successful completion, a value of 0 is returned. Otherwise, a value
of -1 is returned and errno is set to indicate the error.
ERRORS
The gettimeofday() function fails if the following is true:
[EFAULT] Either tp or tzp points to an invalid address.
RELATED INFORMATION
Functions: time(2)
2 Intergraph Corporation - 2/94