1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" 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 2009-03-25 "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)):
65 can get and set the time as well as a timezone.
76 time_t tv_sec; /* seconds */
77 suseconds_t tv_usec; /* microseconds */
82 and gives the number of seconds and microseconds since the Epoch (see
87 .IR "struct timezone" :
92 int tz_minuteswest; /* minutes west of Greenwich */
93 int tz_dsttime; /* type of DST correction */
102 is NULL, the corresponding structure is not set or returned.
103 .\" The following is covered under EPERM below:
105 .\" Only the superuser may use
106 .\" .BR settimeofday ().
110 structure is obsolete; the
112 argument should normally be specified as NULL.
115 field has never been used under Linux; it has not
116 been and will not be supported by libc or glibc.
117 Each and every occurrence of this field in the kernel source
118 (other than the declaration) is a bug.
120 is purely of historic interest.
124 contains a symbolic constant (values are given below)
125 that indicates in which part of the year Daylight Saving Time
127 (Note: its value is constant throughout the year:
128 it does not indicate that DST is in force, it just selects an
130 The daylight saving time algorithms defined are as follows :
134 \fBDST_NONE\fP /* not on dst */
136 \fBDST_USA\fP /* USA style dst */
138 \fBDST_AUST\fP /* Australian style dst */
140 \fBDST_WET\fP /* Western European dst */
142 \fBDST_MET\fP /* Middle European dst */
144 \fBDST_EET\fP /* Eastern European dst */
146 \fBDST_CAN\fP /* Canada */
148 \fBDST_GB\fP /* Great Britain and Eire */
150 \fBDST_RUM\fP /* Rumania */
152 \fBDST_TUR\fP /* Turkey */
154 \fBDST_AUSTALT\fP /* Australian style with shift in 1986 */
158 Of course it turned out that the period in which
159 Daylight Saving Time is in force cannot be given
160 by a simple algorithm, one per country; indeed,
161 this period is determined by unpredictable political
163 So this method of representing timezones
165 Under Linux, in a call to
169 field should be zero.
171 Under Linux there are some peculiar "warp clock" semantics associated
174 system call if on the very first call (after booting)
179 argument is NULL and the
182 In such a case it is assumed that the CMOS clock
183 is on local time, and that it has to be incremented by this amount
184 to get UTC system time.
185 No doubt it is a bad idea to use this feature.
187 Macros for operating on
189 structures are described in
195 return 0 for success, or \-1 for failure (in which case
197 is set appropriately).
205 pointed outside the accessible address space.
208 Timezone (or something else) is invalid.
211 The calling process has insufficient privilege to call
215 capability is required.
218 POSIX.1-2001 describes
224 as obsolete, recomending the use of
225 .BR clock_gettime (2)
229 Traditionally, the fields of
239 .BR capabilities (7),