1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" Modified by Michael Haardt (michael@moria.de)
6 .\" Modified 1993-07-23 by Rik Faith (faith@cs.unc.edu)
7 .\" Modified 1994-08-21 by Michael Chastain (mec@shell.portal.com):
8 .\" Fixed necessary '#include' lines.
9 .\" Modified 1995-04-15 by Michael Chastain (mec@shell.portal.com):
10 .\" Added reference to adjtimex.
11 .\" Removed some nonsense lines pointed out by Urs Thuermann,
12 .\" (urs@isnogud.escape.de), aeb, 950722.
13 .\" Modified 1997-01-14 by Austin Donnelly (and1000@debian.org):
14 .\" Added return values section, and bit on EFAULT
15 .\" Added clarification on timezone, aeb, 971210.
16 .\" Removed "#include <unistd.h>", aeb, 010316.
17 .\" Modified, 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
18 .\" Added notes on capability requirement.
20 .TH GETTIMEOFDAY 2 2021-03-22 "Linux" "Linux Programmer's Manual"
22 gettimeofday, settimeofday \- get / set time
25 .RI ( libc ", " \-lc )
28 .B #include <sys/time.h>
30 .BI "int gettimeofday(struct timeval *restrict " tv ,
31 .BI " struct timezone *restrict " tz );
32 .BI "int settimeofday(const struct timeval *" tv ,
33 .BI " const struct timezone *" tz );
37 Feature Test Macro Requirements for glibc (see
38 .BR feature_test_macros (7)):
45 Glibc 2.19 and earlier:
53 can get and set the time as well as a timezone.
65 time_t tv_sec; /* seconds */
66 suseconds_t tv_usec; /* microseconds */
71 and gives the number of seconds and microseconds since the Epoch (see
77 .IR "struct timezone" :
82 int tz_minuteswest; /* minutes west of Greenwich */
83 int tz_dsttime; /* type of DST correction */
92 is NULL, the corresponding structure is not set or returned.
93 .\" FIXME . The compilation warning looks to be going away in 2.17
94 .\" see glibc commit 4b7634a5e03b0da6f8875de9d3f74c1cf6f2a6e8
95 (However, compilation warnings will result if
98 .\" The following is covered under EPERM below:
100 .\" Only the superuser may use
101 .\" .BR settimeofday ().
105 structure is obsolete; the
107 argument should normally be specified as NULL.
110 Under Linux, there are some peculiar "warp clock" semantics associated
113 system call if on the very first call (after booting)
118 argument is NULL and the
123 field should be zero for this case.)
124 In such a case it is assumed that the CMOS clock
125 is on local time, and that it has to be incremented by this amount
126 to get UTC system time.
127 No doubt it is a bad idea to use this feature.
132 return 0 for success.
133 On error, \-1 is returned and
135 is set to indicate the error.
143 pointed outside the accessible address space.
146 .RB ( settimeofday ()):
151 .RB ( settimeofday ()):
155 is outside the range [0..999,999].
157 .BR EINVAL " (since Linux 4.3)"
158 .\" commit e1d7ba8735551ed79c7a0463a042353574b96da3
159 .RB ( settimeofday ()):
160 An attempt was made to set the time to a value less than
161 the current value of the
164 .BR clock_gettime (2)).
167 The calling process has insufficient privilege to call
171 capability is required.
174 POSIX.1-2001 describes
180 as obsolete, recommending the use of
181 .BR clock_gettime (2)
187 affected by discontinuous jumps in the system time
188 (e.g., if the system administrator manually changes the system time).
189 If you need a monotonically increasing clock, see
190 .BR clock_gettime (2).
192 Macros for operating on
194 structures are described in
197 Traditionally, the fields of
202 .SS C library/kernel differences
203 On some architectures, an implementation of
208 .SS The tz_dsttime field
209 On a non-Linux kernel, with glibc, the
213 will be set to a nonzero value by
215 if the current timezone has ever had or will have a daylight saving
217 In this sense it exactly mirrors the meaning of
219 for the current zone.
220 On Linux, with glibc, the setting of the
224 has never been used by
229 .\" been and will not be supported by libc or glibc.
230 .\" Each and every occurrence of this field in the kernel source
231 .\" (other than the declaration) is a bug.
232 Thus, the following is purely of historical interest.
234 On old systems, the field
236 contains a symbolic constant (values are given below)
237 that indicates in which part of the year Daylight Saving Time
239 (Note: this value is constant throughout the year:
240 it does not indicate that DST is in force, it just selects an
242 The daylight saving time algorithms defined are as follows:
246 \fBDST_NONE\fP /* not on DST */
247 \fBDST_USA\fP /* USA style DST */
248 \fBDST_AUST\fP /* Australian style DST */
249 \fBDST_WET\fP /* Western European DST */
250 \fBDST_MET\fP /* Middle European DST */
251 \fBDST_EET\fP /* Eastern European DST */
252 \fBDST_CAN\fP /* Canada */
253 \fBDST_GB\fP /* Great Britain and Eire */
254 \fBDST_RUM\fP /* Romania */
255 \fBDST_TUR\fP /* Turkey */
256 \fBDST_AUSTALT\fP /* Australian style with shift in 1986 */
260 Of course it turned out that the period in which
261 Daylight Saving Time is in force cannot be given
262 by a simple algorithm, one per country; indeed,
263 this period is determined by unpredictable political
265 So this method of representing timezones
270 .BR clock_gettime (2),
275 .BR capabilities (7),