1GETTIMEOFDAY(2)            Linux Programmer's Manual           GETTIMEOFDAY(2)
2
3
4

NAME

6       gettimeofday, settimeofday - get / set time
7

SYNOPSIS

9       #include <sys/time.h>
10
11       int gettimeofday(struct timeval *tv, struct timezone *tz);
12
13       int settimeofday(const struct timeval *tv, const struct timezone *tz);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       settimeofday():
18           Since glibc 2.19:
19               _DEFAULT_SOURCE
20           Glibc 2.19 and earlier:
21               _BSD_SOURCE
22

DESCRIPTION

24       The  functions  gettimeofday()  and  settimeofday() can get and set the
25       time as well as a timezone.  The tv argument is a  struct  timeval  (as
26       specified in <sys/time.h>):
27
28           struct timeval {
29               time_t      tv_sec;     /* seconds */
30               suseconds_t tv_usec;    /* microseconds */
31           };
32
33       and  gives  the number of seconds and microseconds since the Epoch (see
34       time(2)).  The tz argument is a struct timezone:
35
36           struct timezone {
37               int tz_minuteswest;     /* minutes west of Greenwich */
38               int tz_dsttime;         /* type of DST correction */
39           };
40
41       If either tv or tz is NULL, the corresponding structure is not  set  or
42       returned.  (However, compilation warnings will result if tv is NULL.)
43
44       The  use  of the timezone structure is obsolete; the tz argument should
45       normally be specified as NULL.  (See NOTES below.)
46
47       Under Linux, there are some peculiar "warp clock" semantics  associated
48       with  the  settimeofday()  system call if on the very first call (after
49       booting) that has a non-NULL tz argument, the tv argument is  NULL  and
50       the  tz_minuteswest  field is nonzero.  (The tz_dsttime field should be
51       zero for this case.)  In such a case it is assumed that the CMOS  clock
52       is  on  local time, and that it has to be incremented by this amount to
53       get UTC system time.  No doubt it is a bad idea to use this feature.
54

RETURN VALUE

56       gettimeofday() and settimeofday() return 0 for success, or -1 for fail‐
57       ure (in which case errno is set appropriately).
58

ERRORS

60       EFAULT One of tv or tz pointed outside the accessible address space.
61
62       EINVAL Timezone (or something else) is invalid.
63
64       EPERM  The  calling process has insufficient privilege to call settime‐
65              ofday(); under Linux the CAP_SYS_TIME capability is required.
66

CONFORMING TO

68       SVr4, 4.3BSD.  POSIX.1-2001 describes gettimeofday() but not settimeof‐
69       day().  POSIX.1-2008 marks gettimeofday() as obsolete, recommending the
70       use of clock_gettime(2) instead.
71

NOTES

73       The time returned by gettimeofday() is affected by discontinuous  jumps
74       in  the system time (e.g., if the system administrator manually changes
75       the system time).  If you need a monotonically  increasing  clock,  see
76       clock_gettime(2).
77
78       Macros  for  operating  on  timeval  structures are described in timer‐
79       add(3).
80
81       Traditionally, the fields of struct timeval were of type long.
82
83   C library/kernel differences
84       On some architectures, an implementation of gettimeofday() is  provided
85       in the vdso(7).
86
87   The tz_dsttime field
88       On a non-Linux kernel, with glibc, the tz_dsttime field of struct time‐
89       zone will be set to a nonzero value by gettimeofday()  if  the  current
90       timezone  has ever had or will have a daylight saving rule applied.  In
91       this sense it exactly mirrors the meaning of daylight(3) for  the  cur‐
92       rent  zone.   On Linux, with glibc, the setting of the tz_dsttime field
93       of struct timezone has never been used by settimeofday() or  gettimeof‐
94       day().  Thus, the following is purely of historical interest.
95
96       On old systems, the field tz_dsttime contains a symbolic constant (val‐
97       ues are given below) that indicates in which part of the year  Daylight
98       Saving  Time is in force.  (Note: this value is constant throughout the
99       year: it does not indicate that DST is in force,  it  just  selects  an
100       algorithm.)   The  daylight  saving time algorithms defined are as fol‐
101       lows:
102
103           DST_NONE     /* not on DST */
104           DST_USA      /* USA style DST */
105           DST_AUST     /* Australian style DST */
106           DST_WET      /* Western European DST */
107           DST_MET      /* Middle European DST */
108           DST_EET      /* Eastern European DST */
109           DST_CAN      /* Canada */
110           DST_GB       /* Great Britain and Eire */
111           DST_RUM      /* Romania */
112           DST_TUR      /* Turkey */
113           DST_AUSTALT  /* Australian style with shift in 1986 */
114
115       Of course it turned out that the period in which Daylight  Saving  Time
116       is  in  force  cannot  be given by a simple algorithm, one per country;
117       indeed, this period is determined by unpredictable political decisions.
118       So this method of representing timezones has been abandoned.
119

SEE ALSO

121       date(1),  adjtimex(2),  clock_gettime(2),  time(2), ctime(3), ftime(3),
122       timeradd(3), capabilities(7), time(7), vdso(7), hwclock(8)
123

COLOPHON

125       This page is part of release 4.15 of the Linux  man-pages  project.   A
126       description  of  the project, information about reporting bugs, and the
127       latest    version    of    this    page,    can     be     found     at
128       https://www.kernel.org/doc/man-pages/.
129
130
131
132Linux                             2017-09-15                   GETTIMEOFDAY(2)
Impressum