GETTIMEOFDAY(3B) GETTIMEOFDAY(3B)
gettimeofday, settimeofday - get/set date and time
#include <sys/time.h>
XPG4:
int gettimeofday(struct timeval *tp, void *tzp);
System V:
int gettimeofday(struct timeval *tp, ...);
int settimeofday(struct timeval *tp, ...);
BSD:
int BSDgettimeofday(struct timeval *tp, struct timezone *tzp);
int BSDsettimeofday(struct timeval *tp, struct timezone *tzp);
The system's notion of the current time is obtained with the gettimeofday
and BSDgettimeofday calls. The time is expressed in seconds and
microseconds since midnight (00:00) Coordinated Universal Time (UTC),
January 1, 1970. The resolution for (BSD)gettimeofday is never worse
than 100 HZ (which equals 10 milliseconds). The actual resolution of
(BSD)gettimeofday depends on the timer capability of the underlying
hardware(see timers(5)).
The difference between the calls gettimeofday(settimeofday) and
BSDgettimeofday(BSDsettimeofday) is the additional second argument tzp in
the latter.
In IRIX, the time zone used by each process is determined by the TZ
environment variable. The tzp argument is present in the BSD calls only
for compatibility. It cannot be used to set the time zone for the
system, and so must be zero for settimeofday. If tzp is not zero,
BSDgettimeofday will return an interpretation of the TIMEZONE environment
variable.
The structures pointed to by tp and tzp are defined in <sys/time.h> as:
struct timeval {
time_t tv_sec; /* seconds since Jan. 1, 1970 */
long tv_usec; /* and microseconds */
};
struct timezone {
int tz_minuteswest; /* of Greenwich */
int tz_dsttime; /* type of dst correction to apply */
};
Page 1
GETTIMEOFDAY(3B) GETTIMEOFDAY(3B)
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 Saving time applies locally during the appropriate part of
the year.
Only the super-user may set the time of day or time zone.
These routines emulate the 4.3BSD system calls.
A 0 return value indicates that the call succeeded. A -1 return value
indicates an error occurred, and in this case an error code is stored
into the global variable errno.
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.
[EINVAL] An attempt to change the timezone was made.
date(1), time(2), stime(2), ctime(3C), see timers(5) for details on the
resolution.
PPPPaaaaggggeeee 2222 [ Back ]
|