Displays, gets and sets date and time.
gettimeofday, settimeofday: Standard C Library (libc.a)
ftime: Berkeley Compatibility Library (libbsd.a)
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.
If a recent adjtime subroutine call is causing the clock to be adjusted backwards, it is possible that two closely spaced gettimeofday calls will observe that time has moved backwards. You can set the GETTOD_ADJ_MONOTONIC environment value to cause the returned value to never decrease. After this environment variable is set, the returned value briefly remains constant as necessary to always report a nondecreasing time of day. This extra processing adds significant pathlength to gettimeofday. Although any setting of this environment variable requires this extra processing, setting it to 1 is recommended for future compatibility.
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.
Item | Description |
---|---|
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. |
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.
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.