1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Modified by Michael Haardt (michael@moria.de)
26 .\" Modified 1993-07-23 by Rik Faith (faith@cs.unc.edu)
27 .\" Modified 1994-08-21 by Michael Chastain (mec@shell.portal.com):
28 .\" Fixed necessary '#include' lines.
29 .\" Modified 1995-04-15 by Michael Chastain (mec@shell.portal.com):
30 .\" Added reference to adjtimex.
31 .\" Removed some nonsense lines pointed out by Urs Thuermann,
32 .\" (urs@isnogud.escape.de), aeb, 950722.
33 .\" Modified 1997-01-14 by Austin Donnelly (and1000@debian.org):
34 .\" Added return values section, and bit on EFAULT
35 .\" Added clarification on timezone, aeb, 971210.
36 .\" Removed "#include <unistd.h>", aeb, 010316.
37 .\" Modified, 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
38 .\" Added notes on capability requirement.
40 .TH GETTIMEOFDAY 2 2019-03-06 "Linux" "Linux Programmer's Manual"
42 gettimeofday, settimeofday \- get / set time
45 .B #include <sys/time.h>
47 .BI "int gettimeofday(struct timeval *" tv ", struct timezone *" tz );
49 .BI "int settimeofday(const struct timeval *" tv \
50 ", const struct timezone *" tz );
54 Feature Test Macro Requirements for glibc (see
55 .BR feature_test_macros (7)):
61 Glibc 2.19 and earlier:
68 can get and set the time as well as a timezone.
79 time_t tv_sec; /* seconds */
80 suseconds_t tv_usec; /* microseconds */
85 and gives the number of seconds and microseconds since the Epoch (see
90 .IR "struct timezone" :
95 int tz_minuteswest; /* minutes west of Greenwich */
96 int tz_dsttime; /* type of DST correction */
105 is NULL, the corresponding structure is not set or returned.
106 .\" FIXME . The compilation warning looks to be going away in 2.17
107 .\" see glibc commit 4b7634a5e03b0da6f8875de9d3f74c1cf6f2a6e8
108 (However, compilation warnings will result if
111 .\" The following is covered under EPERM below:
113 .\" Only the superuser may use
114 .\" .BR settimeofday ().
118 structure is obsolete; the
120 argument should normally be specified as NULL.
123 Under Linux, there are some peculiar "warp clock" semantics associated
126 system call if on the very first call (after booting)
131 argument is NULL and the
136 field should be zero for this case.)
137 In such a case it is assumed that the CMOS clock
138 is on local time, and that it has to be incremented by this amount
139 to get UTC system time.
140 No doubt it is a bad idea to use this feature.
145 return 0 for success, or \-1 for failure (in which case
147 is set appropriately).
155 pointed outside the accessible address space.
158 .RB ( settimeofday ()):
163 .RB ( settimeofday ()):
167 is outside the range [0..999,999].
169 .BR EINVAL " (since Linux 4.3)"
170 .\" commit e1d7ba8735551ed79c7a0463a042353574b96da3
171 .RB ( settimeofday ()):
172 An attempt was made to set the time to a value less than
173 the current value of the
176 .BR clock_gettime (2)).
179 The calling process has insufficient privilege to call
183 capability is required.
186 POSIX.1-2001 describes
192 as obsolete, recommending the use of
193 .BR clock_gettime (2)
199 affected by discontinuous jumps in the system time
200 (e.g., if the system administrator manually changes the system time).
201 If you need a monotonically increasing clock, see
202 .BR clock_gettime (2).
204 Macros for operating on
206 structures are described in
209 Traditionally, the fields of
214 .SS C library/kernel differences
215 On some architectures, an implementation of
220 .SS The tz_dsttime field
221 On a non-Linux kernel, with glibc, the
225 will be set to a nonzero value by
227 if the current timezone has ever had or will have a daylight saving
229 In this sense it exactly mirrors the meaning of
231 for the current zone.
232 On Linux, with glibc, the setting of the
236 has never been used by
241 .\" been and will not be supported by libc or glibc.
242 .\" Each and every occurrence of this field in the kernel source
243 .\" (other than the declaration) is a bug.
244 Thus, the following is purely of historical interest.
246 On old systems, the field
248 contains a symbolic constant (values are given below)
249 that indicates in which part of the year Daylight Saving Time
251 (Note: this value is constant throughout the year:
252 it does not indicate that DST is in force, it just selects an
254 The daylight saving time algorithms defined are as follows:
258 \fBDST_NONE\fP /* not on DST */
259 \fBDST_USA\fP /* USA style DST */
260 \fBDST_AUST\fP /* Australian style DST */
261 \fBDST_WET\fP /* Western European DST */
262 \fBDST_MET\fP /* Middle European DST */
263 \fBDST_EET\fP /* Eastern European DST */
264 \fBDST_CAN\fP /* Canada */
265 \fBDST_GB\fP /* Great Britain and Eire */
266 \fBDST_RUM\fP /* Romania */
267 \fBDST_TUR\fP /* Turkey */
268 \fBDST_AUSTALT\fP /* Australian style with shift in 1986 */
272 Of course it turned out that the period in which
273 Daylight Saving Time is in force cannot be given
274 by a simple algorithm, one per country; indeed,
275 this period is determined by unpredictable political
277 So this method of representing timezones
282 .BR clock_gettime (2),
287 .BR capabilities (7),