GETTIMEOFDAY(2) — SYSTEM CALLS
NAME
gettimeofday, settimeofday − get or set the date and time
SYNOPSIS
#include <sys/time.h>
gettimeofday(tp, tzp)
struct timeval ∗tp;
struct timezone ∗tzp;
settimeofday(tp, tzp)
struct timeval ∗tp;
struct timezone ∗tzp;
DESCRIPTION
The system’s notion of the current Greenwich time and the current time zone is obtained with the gettimeofday call, and set with settimeofday. The current time is expressed in elapsed seconds and microseconds since, January 1, 1970 (zero hour). The resolution of the system clock is hardware dependent; the time may be updated continuously, or in “ticks.”
The structures pointed to by tp and tzp are defined in <sys/time.h> as:
struct timeval {
longtv_sec;/∗ seconds since Jan. 1, 1970 ∗/
longtv_usec;/∗ and microseconds ∗/
};
struct timezone {
inttz_minuteswest;/∗ of Greenwich ∗/
inttz_dsttime;/∗ type of dst correction to apply ∗/
};
The timezone structure indicates the local time zone (measured in minutes westward from Greenwich), and flag that indicates the type of Daylight Saving Time correction to apply. Note that this flag does not indicate whether DST is currently in effect.
If tzp is a zero pointer, the timezone information is not returned or set.
Only the super-user may set the time of day or the time zone.
RETURN
A −1 return value indicates an error occurred; in this case an error code is stored in the global variable errno. Other return codes indicate the type of Daylight Savings Time currently in effect (as defined in /usr/include/sys/time.h):
0DST_NONE: Daylight Savings Time not observed
1DST_USA: United States DST
2DST_AUST: Australian DST
3DST_WET: Western European DST
4DST_MET: Middle European DST
5DST_EET: Eastern European DST
6DST_CAN: Canadian DST
7DST_GB: Great Britian and Eire DST
8DST_RUM: Rumanian DST
9DST_TUR: Turkish DST
10DST_AUSTALT: Australian-style DST with shift in 1986
ERRORS
The following error codes may be set in errno:
EFAULT An argument address referenced invalid memory.
EPERM A user other than the super-user attempted to set the time.
SEE ALSO
BUGS
Time is never correct enough to believe the microsecond values. There should a mechanism by which, at least, local clusters of systems might synchronize their clocks to millisecond granularity.
Daylight Savings Time correction tables aren’t guaranteed to be correct for specific locales.
Sun Release 3.4 — Last change: 5 February 1987