Node:High-Resolution Calendar, Next:Broken-down Time, Previous:Simple Calendar Time, Up:Calendar Time
The time_t
data type used to represent simple times has a
resolution of only one second. Some applications need more precision.
So, the GNU C library also contains functions which are capable of
representing calendar times to a higher resolution than one second. The
functions and the associated data types described in this section are
declared in sys/time.h
.
struct timezone | Data Type |
The struct timezone structure is used to hold minimal information
about the local time zone. It has the following members:
The |
int gettimeofday (struct timeval *tp, struct timezone *tzp) | Function |
The gettimeofday function returns the current calendar time as
the elapsed time since the epoch in the struct timeval structure
indicated by tp. (see Elapsed Time for a description of
struct timespec ). Information about the time zone is returned in
the structure pointed at tzp. If the tzp argument is a null
pointer, time zone information is ignored.
The return value is
|
int settimeofday (const struct timeval *tp, const struct timezone *tzp) | Function |
The settimeofday function sets the current calendar time in the
system clock according to the arguments. As for gettimeofday ,
the calendar time is represented as the elapsed time since the epoch.
As for gettimeofday , time zone information is ignored if
tzp is a null pointer.
You must be a privileged user in order to use Some kernels automatically set the system clock from some source such as
a hardware clock when they start up. Others, including Linux, place the
system clock in an "invalid" state (in which attempts to read the clock
fail). A call of
With a Linux kernel, The return value is
|
int adjtime (const struct timeval *delta, struct timeval *olddelta) | Function |
This function speeds up or slows down the system clock in order to make
a gradual adjustment. This ensures that the calendar time reported by
the system clock is always monotonically increasing, which might not
happen if you simply set the clock.
The delta argument specifies a relative adjustment to be made to the clock time. If negative, the system clock is slowed down for a while until it has lost this much elapsed time. If positive, the system clock is speeded up for a while. If the olddelta argument is not a null pointer, the This function is typically used to synchronize the clocks of computers in a local network. You must be a privileged user to use it. With a Linux kernel, you can use the The return value is
|
Portability Note: The gettimeofday
, settimeofday
,
and adjtime
functions are derived from BSD.
Symbols for the following function are declared in sys/timex.h
.
int adjtimex (struct timex *timex) | Function |
This function is present only with a Linux kernel. |