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(): _BSD_SOURCE
18

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

CONFORMING TO

64       SVr4, 4.3BSD.  POSIX.1-2001 describes gettimeofday() but not settimeof‐
65       day().  POSIX.1-2008 marks gettimeofday() as obsolete, recommending the
66       use of clock_gettime(2) instead.
67

NOTES

69       The time returned by gettimeofday() is affected by discontinuous  jumps
70       in  the system time (e.g., if the system administrator manually changes
71       the system time).  If you need a monotonically  increasing  clock,  see
72       clock_gettime(2).
73
74       Macros  for  operating  on  timeval  structures are described in timer‐
75       add(3).
76
77       Traditionally, the fields of struct timeval were of type long.
78
79       The tz_dsttime field has never been used under Linux.  Thus,  the  fol‐
80       lowing is purely of historic interest.
81
82       On old systems, the field tz_dsttime contains a symbolic constant (val‐
83       ues are given below) that indicates in which part of the year  Daylight
84       Saving  Time is in force.  (Note: this value is constant throughout the
85       year: it does not indicate that DST is in force,  it  just  selects  an
86       algorithm.)   The  daylight  saving time algorithms defined are as fol‐
87       lows:
88
89           DST_NONE     /* not on DST */
90           DST_USA      /* USA style DST */
91           DST_AUST     /* Australian style DST */
92           DST_WET      /* Western European DST */
93           DST_MET      /* Middle European DST */
94           DST_EET      /* Eastern European DST */
95           DST_CAN      /* Canada */
96           DST_GB       /* Great Britain and Eire */
97           DST_RUM      /* Romania */
98           DST_TUR      /* Turkey */
99           DST_AUSTALT  /* Australian style with shift in 1986 */
100
101       Of course it turned out that the period in which Daylight  Saving  Time
102       is  in  force  cannot  be given by a simple algorithm, one per country;
103       indeed, this period is determined by unpredictable political decisions.
104       So this method of representing timezones has been abandoned.
105

SEE ALSO

107       date(1),  adjtimex(2),  clock_gettime(2),  time(2), ctime(3), ftime(3),
108       timeradd(3), capabilities(7), time(7)
109

COLOPHON

111       This page is part of release 3.53 of the Linux  man-pages  project.   A
112       description  of  the project, and information about reporting bugs, can
113       be found at http://www.kernel.org/doc/man-pages/.
114
115
116
117Linux                             2012-04-26                   GETTIMEOFDAY(2)
Impressum