1time.h(0P) POSIX Programmer's Manual time.h(0P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 time.h — time types
14
16 #include <time.h>
17
19 Some of the functionality described on this reference page extends the
20 ISO C standard. Applications shall define the appropriate feature test
21 macro (see the System Interfaces volume of POSIX.1‐2008, Section 2.2,
22 The Compilation Environment) to enable the visibility of these symbols
23 in this header.
24
25 The <time.h> header shall define the clock_t, size_t, time_t, types as
26 described in <sys/types.h>.
27
28 The <time.h> header shall define the clockid_t and timer_t types as
29 described in <sys/types.h>.
30
31 The <time.h> header shall define the locale_t type as described in
32 <locale.h>.
33
34 The <time.h> header shall define the pid_t type as described in
35 <sys/types.h>.
36
37 The tag sigevent shall be declared as naming an incomplete structure
38 type, the contents of which are described in the <signal.h> header.
39
40 The <time.h> header shall declare the tm structure, which shall include
41 at least the following members:
42
43 int tm_sec Seconds [0,60].
44 int tm_min Minutes [0,59].
45 int tm_hour Hour [0,23].
46 int tm_mday Day of month [1,31].
47 int tm_mon Month of year [0,11].
48 int tm_year Years since 1900.
49 int tm_wday Day of week [0,6] (Sunday =0).
50 int tm_yday Day of year [0,365].
51 int tm_isdst Daylight Savings flag.
52
53 The value of tm_isdst shall be positive if Daylight Savings Time is in
54 effect, 0 if Daylight Savings Time is not in effect, and negative if
55 the information is not available.
56
57 The <time.h> header shall declare the timespec structure, which shall
58 include at least the following members:
59
60 time_t tv_sec Seconds.
61 long tv_nsec Nanoseconds.
62
63 The <time.h> header shall also declare the itimerspec structure, which
64 shall include at least the following members:
65
66 struct timespec it_interval Timer period.
67 struct timespec it_value Timer expiration.
68
69 The <time.h> header shall define the following macros:
70
71 NULL As described in <stddef.h>.
72
73 CLOCKS_PER_SEC
74 A number used to convert the value returned by the
75 clock() function into seconds. The value shall be an
76 expression with type clock_t. The value of
77 CLOCKS_PER_SEC shall be 1 million on XSI-conformant sys‐
78 tems. However, it may be variable on other systems, and
79 it should not be assumed that CLOCKS_PER_SEC is a com‐
80 pile-time constant.
81
82 The <time.h> header shall define the following symbolic constants. The
83 values shall have a type that is assignment-compatible with clockid_t.
84
85 CLOCK_MONOTONIC
86 The identifier for the system-wide monotonic clock, which
87 is defined as a clock measuring real time, whose value
88 cannot be set via clock_settime() and which cannot have
89 negative clock jumps. The maximum possible clock jump
90 shall be implementation-defined.
91
92 CLOCK_PROCESS_CPUTIME_ID
93 The identifier of the CPU-time clock associated with the
94 process making a clock() or timer*() function call.
95
96 CLOCK_REALTIME
97 The identifier of the system-wide clock measuring real
98 time.
99
100 CLOCK_THREAD_CPUTIME_ID
101 The identifier of the CPU-time clock associated with the
102 thread making a clock() or timer*() function call.
103
104 The <time.h> header shall define the following symbolic constant:
105
106 TIMER_ABSTIME Flag indicating time is absolute. For functions taking
107 timer objects, this refers to the clock associated with
108 the timer.
109
110 The <time.h> header shall provide a declaration or definition for get‐
111 date_err. The getdate_err symbol shall expand to an expression of type
112 int. It is unspecified whether getdate_err is a macro or an identifier
113 declared with external linkage, and whether or not it is a modifiable
114 lvalue. If a macro definition is suppressed in order to access an
115 actual object, or a program defines an identifier with the name get‐
116 date_err, the behavior is undefined.
117
118 The following shall be declared as functions and may also be defined as
119 macros. Function prototypes shall be provided.
120
121 char *asctime(const struct tm *);
122 char *asctime_r(const struct tm *restrict, char *restrict);
123 clock_t clock(void);
124 int clock_getcpuclockid(pid_t, clockid_t *);
125 int clock_getres(clockid_t, struct timespec *);
126 int clock_gettime(clockid_t, struct timespec *);
127 int clock_nanosleep(clockid_t, int, const struct timespec *,
128 struct timespec *);
129 int clock_settime(clockid_t, const struct timespec *);
130 char *ctime(const time_t *);
131 char *ctime_r(const time_t *, char *);
132 double difftime(time_t, time_t);
133 struct tm *getdate(const char *);
134 struct tm *gmtime(const time_t *);
135 struct tm *gmtime_r(const time_t *restrict, struct tm *restrict);
136 struct tm *localtime(const time_t *);
137 struct tm *localtime_r(const time_t *restrict, struct tm *restrict);
138 time_t mktime(struct tm *);
139 int nanosleep(const struct timespec *, struct timespec *);
140 size_t strftime(char *restrict, size_t, const char *restrict,
141 const struct tm *restrict);
142 size_t strftime_l(char *restrict, size_t, const char *restrict,
143 const struct tm *restrict, locale_t);
144 char *strptime(const char *restrict, const char *restrict,
145 struct tm *restrict);
146 time_t time(time_t *);
147 int timer_create(clockid_t, struct sigevent *restrict,
148 timer_t *restrict);
149 int timer_delete(timer_t);
150 int timer_getoverrun(timer_t);
151 int timer_gettime(timer_t, struct itimerspec *);
152 int timer_settime(timer_t, int, const struct itimerspec *restrict,
153 struct itimerspec *restrict);
154 void tzset(void);
155
156 The <time.h> header shall declare the following as variables:
157
158 extern int daylight;
159 extern long timezone;
160 extern char *tzname[];
161
162 Inclusion of the <time.h> header may make visible all symbols from the
163 <signal.h> header.
164
165 The following sections are informative.
166
168 The range [0,60] for tm_sec allows for the occasional leap second.
169
170 tm_year is a signed value; therefore, years before 1900 may be repre‐
171 sented.
172
173 To obtain the number of clock ticks per second returned by the times()
174 function, applications should call sysconf(_SC_CLK_TCK).
175
177 The range [0,60] seconds allows for positive or negative leap seconds.
178 The formal definition of UTC does not permit double leap seconds, so
179 all mention of double leap seconds has been removed, and the range
180 shortened from the former [0,61] seconds seen in earlier versions of
181 this standard.
182
184 None.
185
187 <locale.h>, <signal.h>, <stddef.h>, <sys_types.h>
188
189 The System Interfaces volume of POSIX.1‐2008, Section 2.2, The Compila‐
190 tion Environment, asctime(), clock(), clock_getcpuclockid(),
191 clock_getres(), clock_nanosleep(), ctime(), difftime(), getdate(),
192 gmtime(), localtime(), mktime(), mq_receive(), mq_send(), nanosleep(),
193 pthread_getcpuclockid(), pthread_mutex_timedlock(),
194 pthread_rwlock_timedrdlock(), pthread_rwlock_timedwrlock(), sem_timed‐
195 wait(), strftime(), strptime(), sysconf(), time(), timer_create(),
196 timer_delete(), timer_getoverrun(), tzset(), utime()
197
199 Portions of this text are reprinted and reproduced in electronic form
200 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
201 -- Portable Operating System Interface (POSIX), The Open Group Base
202 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
203 cal and Electronics Engineers, Inc and The Open Group. (This is
204 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
205 event of any discrepancy between this version and the original IEEE and
206 The Open Group Standard, the original IEEE and The Open Group Standard
207 is the referee document. The original Standard can be obtained online
208 at http://www.unix.org/online.html .
209
210 Any typographical or formatting errors that appear in this page are
211 most likely to have been introduced during the conversion of the source
212 files to man page format. To report such errors, see https://www.ker‐
213 nel.org/doc/man-pages/reporting_bugs.html .
214
215
216
217IEEE/The Open Group 2013 time.h(0P)