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 *restrict tv,
12                        struct timezone *restrict tz);
13       int settimeofday(const struct timeval *tv,
14                        const struct timezone *tz);
15
16   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18       settimeofday():
19           Since glibc 2.19:
20               _DEFAULT_SOURCE
21           Glibc 2.19 and earlier:
22               _BSD_SOURCE
23

DESCRIPTION

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

RETURN VALUE

60       gettimeofday()  and  settimeofday() return 0 for success.  On error, -1
61       is returned and errno is set to indicate the error.
62

ERRORS

64       EFAULT One of tv or tz pointed outside the accessible address space.
65
66       EINVAL (settimeofday()): timezone is invalid.
67
68       EINVAL (settimeofday()): tv.tv_sec is negative or tv.tv_usec is outside
69              the range [0..999,999].
70
71       EINVAL (since Linux 4.3)
72              (settimeofday()): An attempt was made to set the time to a value
73              less than the current value of the  CLOCK_MONOTONIC  clock  (see
74              clock_gettime(2)).
75
76       EPERM  The  calling process has insufficient privilege to call settime‐
77              ofday(); under Linux the CAP_SY