[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1


gettimeofday, settimeofday, or ftime Subroutine

Purpose

Displays, gets and sets date and time.

Libraries

gettimeofday, settimeofday: Standard C Library (libc.a)

ftime: Berkeley Compatibility Library (libbsd.a)

Syntax


#include <sys/time.h>
int gettimeofday ( Tp, Tzp)
struct timeval *Tp;
void *Tzp;
int settimeofday (TpTzp)
struct timeval *Tp;
struct timezone *Tzp;

#include <sys/types.h>
#include <sys/timeb.h>
int ftime (Tp)
struct timeb *Tp;

Description

Current Greenwich time and the current time zone are displayed with the gettimeofday subroutine, and set with the settimeofday subroutine. 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 either continuously or in "ticks." If the Tzp parameter has a value of 0, the time zone information is not returned or set.

The Tp parameter returns a pointer to a timeval structure that contains the time since the epoch began in seconds and microseconds.

The timezone structure indicates both 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.

In addition to the difference in timer granularity, the timezone structure distinguishes these subroutines from the POSIX gettimer and settimer subroutines, which deal strictly with Greenwich Mean Time.

The ftime subroutine fills in a structure pointed to by its argument, as defined by <sys/timeb.h>. The structure contains the time in seconds since 00:00:00 UTC (Coordinated Universal Time), January 1, 1970, up to 1000 milliseconds of more-precise interval, the local timezone (measured in minutes of time westward from UTC), and a flag that, if nonzero, indicates that Daylight Saving time is in effect, and the values stored in the timeb structure have been adjusted accordingly.

Parameters


Tp Pointer to a timeval structure, defined in the sys/time.h file.
Tzp Pointer to a timezone structure, defined in the sys/time.h file.

Return Values

If the subroutine succeeds, a value of 0 is returned. If an error occurs, a value of -1 is returned and errno is set to indicate the error.

Error Codes

If the settimeofday subroutine is unsuccessful, the errno value is set to EPERM to indicate that the process's effective user ID does not have root user authority.

No errors are defined for the gettimeofday or ftime subroutine.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]