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       int settimeofday(const struct timeval *tv , const struct timezone *tz);
13

DESCRIPTION

15       The  functions  gettimeofday()  and  settimeofday() can get and set the
16       time as well as a timezone.  The tv argument is a  struct  timeval  (as
17       specified  in <sys/time.h>):
18
19         struct timeval {
20             time_t      tv_sec;     /* seconds */
21             suseconds_t tv_usec;    /* microseconds */
22         };
23
24       and  gives  the number of seconds and microseconds since the Epoch (see
25       time(2)).  The tz argument is a struct timezone:
26
27         struct timezone {
28             int tz_minuteswest;     /* minutes west of Greenwich */
29             int tz_dsttime;         /* type of DST correction */
30         };
31
32       If either tv or tz is NULL, the corresponding structure is not  set  or
33       returned.
34
35       The  use  of the timezone structure is obsolete; the tz argument should
36       normally be specified as NULL.  The tz_dsttime  field  has  never  been
37       used  under Linux; it has not been and will not be supported by libc or
38       glibc.  Each and every occurrence of this field in  the  kernel  source
39       (other than the declaration) is a bug. Thus, the following is purely of
40       historic interest.
41
42       The field tz_dsttime contains a symbolic  constant  (values  are  given
43       below) that indicates in which part of the year Daylight Saving Time is
44       in force. (Note: its value is constant throughout the year: it does not
45       indicate that DST is in force, it just selects an algorithm.)  The day‐
46       light saving time algorithms defined are as follows :
47
48        DST_NONE    /* not on dst */
49        DST_USA     /* USA style dst */
50        DST_AUST    /* Australian style dst */
51        DST_WET     /* Western European dst */
52        DST_MET     /* Middle European dst */
53        DST_EET     /* Eastern European dst */
54        DST_CAN     /* Canada */
55        DST_GB      /* Great Britain and Eire */
56        DST_RUM     /* Rumania */
57        DST_TUR     /* Turkey */
58        DST_AUSTALT /* Australian style with shift in 1986 */
59
60       Of course it turned out that the period in which Daylight  Saving  Time
61       is  in  force  cannot  be given by a simple algorithm, one per country;
62       indeed, this period is determined by unpredictable political decisions.
63       So  this  method  of  representing time zones has been abandoned. Under
64       Linux, in a call to settimeofday() the tz_dsttime field should be zero.
65
66       Under Linux there is some peculiar `warp clock' semantics associated to
67       the  settimeofday()  system call if on the very first call (after boot‐
68       ing) that has a non-NULL tz argument, the tv argument is NULL  and  the
69       tz_minuteswest field is non-zero. In such a case it is assumed that the
70       CMOS clock is on local time, and that it has to be incremented by  this
71       amount  to  get UTC system time.  No doubt it is a bad idea to use this
72       feature.
73
74       The following macros are defined to operate on a struct timeval:
75
76       #define timerisset(tvp)\
77               ((tvp)->tv_sec || (tvp)->tv_usec)
78       #define timercmp(tvp, uvp, cmp)\
79               ((tvp)->tv_sec cmp (uvp)->tv_sec ||\
80               (tvp)->tv_sec == (uvp)->tv_sec &&\
81               (tvp)->tv_usec cmp (uvp)->tv_usec)
82       #define timerclear(tvp)\
83               ((tvp)->tv_sec = (tvp)->tv_usec = 0)
84

RETURN VALUE

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

ERRORS

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

NOTE

98       The prototype for settimeofday() and the defines for timercmp, timeris‐
99       set,  timerclear, timeradd, timersub are (since glibc2.2.2) only avail‐
100       able if _BSD_SOURCE is defined.
101
102       Traditionally, the fields of struct timeval were longs.
103

CONFORMING TO

105       SVr4, 4.3BSD.  POSIX.1-2001 describes gettimeofday() but not settimeof‐
106       day().
107

SEE ALSO

109       date(1),  adjtimex(2),  time(2),  ctime(3),  ftime(3), capabilities(7),
110       time(7)
111
112
113
114Linux 2.6.6                       2004-05-27                   GETTIMEOFDAY(2)
Impressum