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.
39
40       The  use  of the timezone structure is obsolete; the tz argument should
41       normally be specified as NULL.  The tz_dsttime  field  has  never  been
42       used  under Linux; it has not been and will not be supported by libc or
43       glibc.  Each and every occurrence of this field in  the  kernel  source
44       (other  than  the declaration) is a bug.  Thus, the following is purely
45       of historic interest.
46
47       The field tz_dsttime contains a symbolic  constant  (values  are  given
48       below) that indicates in which part of the year Daylight Saving Time is
49       in force.  (Note: its value is constant throughout the  year:  it  does
50       not  indicate that DST is in force, it just selects an algorithm.)  The
51       daylight saving time algorithms defined are as follows :
52
53           DST_NONE     /* not on dst */
54           DST_USA      /* USA style dst */
55           DST_AUST     /* Australian style dst */
56           DST_WET      /* Western European dst */
57           DST_MET      /* Middle European dst */
58           DST_EET      /* Eastern European dst */
59           DST_CAN      /* Canada */
60           DST_GB       /* Great Britain and Eire */
61           DST_RUM      /* Rumania */
62           DST_TUR      /* Turkey */
63           DST_AUSTALT  /* Australian style with shift in 1986 */
64
65       Of course it turned out that the period in which Daylight  Saving  Time
66       is  in  force  cannot  be given by a simple algorithm, one per country;
67       indeed, this period is determined by unpredictable political decisions.
68       So  this  method  of  representing timezones has been abandoned.  Under
69       Linux, in a call to settimeofday() the tz_dsttime field should be zero.
70
71       Under Linux there are some peculiar "warp clock"  semantics  associated
72       with  the  settimeofday()  system call if on the very first call (after
73       booting) that has a non-NULL tz argument, the tv argument is  NULL  and
74       the tz_minuteswest field is nonzero.  In such a case it is assumed that
75       the CMOS clock is on local time, and that it has to be  incremented  by
76       this  amount  to get UTC system time.  No doubt it is a bad idea to use
77       this feature.
78
79       Macros for operating on timeval  structures  are  described  in  timer‐
80       add(3).
81

RETURN VALUE

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

ERRORS

87       EFAULT One of tv or tz pointed outside the accessible address space.
88
89       EINVAL Timezone (or something else) is invalid.
90
91       EPERM  The calling process has insufficient privilege to call  settime‐
92              ofday(); under Linux the CAP_SYS_TIME capability is required.
93

CONFORMING TO

95       SVr4, 4.3BSD.  POSIX.1-2001 describes gettimeofday() but not settimeof‐
96       day().  POSIX.1-2008 marks gettimeofday() as obsolete, recommending the
97       use of clock_gettime(2) instead.
98

NOTES

100       Traditionally, the fields of struct timeval were of type long.
101

SEE ALSO

103       date(1),  adjtimex(2),  time(2),  ctime(3),  ftime(3), capabilities(7),
104       time(7)
105

COLOPHON

107       This page is part of release 3.25 of the Linux  man-pages  project.   A
108       description  of  the project, and information about reporting bugs, can
109       be found at http://www.kernel.org/doc/man-pages/.
110
111
112
113Linux                             2009-03-25                   GETTIMEOFDAY(2)
Impressum