gettimeofday()

NAME

gettimeofday() - get date and time

SYNOPSIS

#include <sys/time.h>

int gettimeofday (struct timeval *tp, void *tzp)

DESCRIPTION

The system's notion of the current Greenwich time and the current time zone is obtained with the gettimeofday(3) call. The time is expressed in seconds and microseconds since midnight (0 hour), January 1, 1970. The resolution of the system clock is hardware dependent, and the time may be updated continuously or in ticks. If tp or tzp is NULL, the associated time information will not be returned.

The timeval structure is defined in <sys/time.h> as:

struct timeval {
	 long tv_sec; 	/* seconds since Jan. 1, 1970 */
	 long tv_usec;  /* and microseconds */
};

The tzp argument is no longer supported; any value passed in is ignored.

RETURN VALUE

The function returns 0 on success. On failure, they return -1 and set the global variable errno to indicate the error.

ERRORS

The following error codes may be set in errno:

[EFAULT]
An argument address referenced invalid memory.
[EPERM]
A user without appropriate privileges attempted to set the time.

NOTES

The tzp argument used to be a struct timezone:

struct timezone {
	 int  tz_minuteswest; /* of Greenwich */
	 int  tz_dsttime; /* type of dst correction to apply */
};

If non-zero, the tz_dsttime indicated that Daylight Savings time applied locally during the appropriate time of the year.

SEE ALSO

date(1)

ctime(3)