gettimeofday(), gettimeofday64() — Get date and time
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2
Single UNIX Specification, Version 3 Language Environment® |
both |
Format
#define _XOPEN_SOURCE_EXTENDED 1
#undef _ALL_SOURCE
#include <sys/time.h>
int gettimeofday(struct timeval *__restrict__ tp,
void *__restrict__ tzp);
#define _ALL_SOURCE
#include <sys/time.h>
int gettimeofday(struct timeval *__restrict__ tp,
struct timezone *__restrict__ tzp);
#define _LARGE_TIME_API
#include <time.h>
int gettimeofday64(struct timeval64 *__restrict__ tp,
void *__restrict__ tzp);
General description
The gettimeofday() function obtains the current time, expressed as seconds and microseconds since 00:00:00 Coordinated Universal Time (UTC), January 1, 1970, and stores it in the timeval structure pointed to by tp.
Special behavior for _ALL_SOURCE: The gettimeofday() function has two prototypes. Which one is used depends on whether or not you define the _ALL_SOURCE feature test macro when you compile your program. If _ALL_SOURCE is NOT defined when the C/370 preprocessor processes the <sys/time.h> header, it includes a prototype for gettimeofday() which defines the second argument, tzp, as a void pointer and includes a C/370 pragma map statement for a C/370 version of gettimeofday() which ignores tzp.
int tz_minuteswest; /* Time west of Greenwich in minutes */
int tz_dsttime; /* Type of DST correction to apply */
When
_ALL_SOURCE is defined, the gettimeofday() function: - invokes tzset() to set the values of the timezone and daylight external variables.
- converts the value of the timezone external variable to minutes and stores the converted value, rounded up to the nearest minute, in tzp->tz_minuteswest.
- stores the value of the daylight external variable in tzp->tz_dsttime.
The function gettimeofday64() will behave exactly like gettimeofday() except it will support calendar times beyond 03:14:07 UTC on January 19, 2038.
There is no support for an _ALL_SOURCE version of gettimeofday64().
Returned value
If successful, gettimeofday() returns 0.
If overflow occurs, gettimeofday() returns nonzero. Overflow occurs when the current time in seconds since 00:00:00 UTC, January 1, 1970 exceeds the capacity of the tv_sec member of the timeval structure pointed to by tp. The tv_sec member is type time_t.