]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
2 | .\" | |
5fbde956 | 3 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da MK |
4 | .\" |
5 | .\" References consulted: | |
6 | .\" Linux libc source code | |
7 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
8 | .\" 386BSD man pages | |
9 | .\" Modified Sat Jul 24 19:49:27 1993 by Rik Faith (faith@cs.unc.edu) | |
10 | .\" Modified Fri Apr 26 12:38:55 MET DST 1996 by Martin Schulze (joey@linux.de) | |
11 | .\" Modified 2001-11-13, aeb | |
12 | .\" Modified 2001-12-13, joey, aeb | |
3e53c142 | 13 | .\" Modified 2004-11-16, mtk |
fea681da | 14 | .\" |
4c1c5274 | 15 | .TH ctime 3 (date) "Linux man-pages (unreleased)" |
fea681da MK |
16 | .SH NAME |
17 | asctime, ctime, gmtime, localtime, mktime, asctime_r, ctime_r, gmtime_r, | |
18 | localtime_r \- transform date and time to broken-down time or ASCII | |
b813014f AC |
19 | .SH LIBRARY |
20 | Standard C library | |
21 | .RI ( libc ", " \-lc ) | |
fea681da MK |
22 | .SH SYNOPSIS |
23 | .nf | |
24 | .B #include <time.h> | |
68e4db0a | 25 | .PP |
fea681da | 26 | .BI "char *asctime(const struct tm *" tm ); |
bd99e6b7 AC |
27 | .BI "char *asctime_r(const struct tm *restrict " tm , |
28 | .BI " char " buf "[restrict 26]);" | |
68e4db0a | 29 | .PP |
fea681da | 30 | .BI "char *ctime(const time_t *" timep ); |
bd99e6b7 AC |
31 | .BI "char *ctime_r(const time_t *restrict " timep , |
32 | .BI " char " buf "[restrict 26]);" | |
68e4db0a | 33 | .PP |
fea681da | 34 | .BI "struct tm *gmtime(const time_t *" timep ); |
cd7ebdf9 AC |
35 | .BI "struct tm *gmtime_r(const time_t *restrict " timep , |
36 | .BI " struct tm *restrict " result ); | |
68e4db0a | 37 | .PP |
fea681da | 38 | .BI "struct tm *localtime(const time_t *" timep ); |
cd7ebdf9 AC |
39 | .BI "struct tm *localtime_r(const time_t *restrict " timep , |
40 | .BI " struct tm *restrict " result ); | |
68e4db0a | 41 | .PP |
fea681da MK |
42 | .BI "time_t mktime(struct tm *" tm ); |
43 | .fi | |
68e4db0a | 44 | .PP |
d39ad78f | 45 | .RS -4 |
cc4615cc MK |
46 | Feature Test Macro Requirements for glibc (see |
47 | .BR feature_test_macros (7)): | |
d39ad78f | 48 | .RE |
68e4db0a | 49 | .PP |
cc4615cc MK |
50 | .BR asctime_r (), |
51 | .BR ctime_r (), | |
52 | .BR gmtime_r (), | |
53 | .BR localtime_r (): | |
9d2adbae MK |
54 | .nf |
55 | _POSIX_C_SOURCE | |
56 | || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE | |
57 | .fi | |
fea681da | 58 | .SH DESCRIPTION |
60a90ecd MK |
59 | The |
60 | .BR ctime (), | |
d556548b | 61 | .BR gmtime (), |
60a90ecd MK |
62 | and |
63 | .BR localtime () | |
64 | functions all take | |
213d2580 | 65 | an argument of data type \fItime_t\fP, which represents calendar time. |
fea681da | 66 | When interpreted as an absolute time value, it represents the number of |
f49c451a | 67 | seconds elapsed since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). |
fea681da | 68 | .PP |
60a90ecd MK |
69 | The |
70 | .BR asctime () | |
71 | and | |
72 | .BR mktime () | |
73 | functions both take an argument | |
213d2580 | 74 | representing broken-down time, which is a representation |
1c2816e2 | 75 | separated into year, month, day, and so on. |
fea681da | 76 | .PP |
cf96188b AC |
77 | Broken-down time is stored in the structure |
78 | .IR tm , | |
79 | described in | |
80 | .BR tm (3type). | |
fea681da MK |
81 | .PP |
82 | The call | |
83 | .BI ctime( t ) | |
84 | is equivalent to | |
85 | .BI asctime(localtime( t )) \fR. | |
0e8fe3b4 MK |
86 | It converts the calendar time \fIt\fP into a |
87 | null-terminated string of the form | |
ba39b288 MK |
88 | .PP |
89 | .in +4n | |
90 | .EX | |
d1a71985 | 91 | "Wed Jun 30 21:49:08 1993\en" |
ba39b288 | 92 | .EE |
a202ed93 | 93 | .in |
ba39b288 | 94 | .PP |
84c517a4 MK |
95 | The abbreviations for the days of the week are "Sun", "Mon", "Tue", "Wed", |
96 | "Thu", "Fri", and "Sat". | |
97 | The abbreviations for the months are "Jan", | |
98 | "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", and | |
99 | "Dec". | |
c13182ef | 100 | The return value points to a statically allocated string which |
fea681da | 101 | might be overwritten by subsequent calls to any of the date and time |
c13182ef | 102 | functions. |
546f67f3 MK |
103 | The function also sets the external |
104 | variables \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP (see | |
fea681da | 105 | .BR tzset (3)) |
5b0dc1ba | 106 | with information about the current timezone. |
da27f178 | 107 | The reentrant version |
60a90ecd MK |
108 | .BR ctime_r () |
109 | does the same, but stores the | |
ef38dda0 MK |
110 | string in a user-supplied buffer |
111 | which should have room for at least 26 bytes. | |
c13182ef | 112 | It need not |
546f67f3 | 113 | set \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP. |
fea681da | 114 | .PP |
60a90ecd MK |
115 | The |
116 | .BR gmtime () | |
117 | function converts the calendar time \fItimep\fP to | |
fea681da | 118 | broken-down time representation, expressed in Coordinated Universal Time |
c13182ef MK |
119 | (UTC). |
120 | It may return NULL when the year does not fit into an integer. | |
fea681da MK |
121 | The return value points to a statically allocated struct which might be |
122 | overwritten by subsequent calls to any of the date and time functions. | |
60a90ecd MK |
123 | The |
124 | .BR gmtime_r () | |
125 | function does the same, but stores the data in a | |
fea681da MK |
126 | user-supplied struct. |
127 | .PP | |
60a90ecd MK |
128 | The |
129 | .BR localtime () | |
130 | function converts the calendar time \fItimep\fP to | |
5f14486c MK |
131 | broken-down time representation, |
132 | expressed relative to the user's specified timezone. | |
c13182ef | 133 | The function acts as if it called |
fea681da | 134 | .BR tzset (3) |
c13182ef | 135 | and sets the external variables \fItzname\fP with |
5b0dc1ba | 136 | information about the current timezone, \fItimezone\fP with the difference |
fea681da | 137 | between Coordinated Universal Time (UTC) and local standard time in |
c7094399 | 138 | seconds, and \fIdaylight\fP to a nonzero value if daylight savings |
fea681da MK |
139 | time rules apply during some part of the year. |
140 | The return value points to a statically allocated struct which might be | |
141 | overwritten by subsequent calls to any of the date and time functions. | |
60a90ecd MK |
142 | The |
143 | .BR localtime_r () | |
144 | function does the same, but stores the data in a | |
c13182ef | 145 | user-supplied struct. |
546f67f3 | 146 | It need not set \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP. |
fea681da | 147 | .PP |
60a90ecd MK |
148 | The |
149 | .BR asctime () | |
150 | function converts the broken-down time value | |
0e8fe3b4 | 151 | \fItm\fP into a null-terminated string with the same format as |
60a90ecd | 152 | .BR ctime (). |
c13182ef | 153 | The return value points to a statically allocated string which might be |
fea681da | 154 | overwritten by subsequent calls to any of the date and time functions. |
60a90ecd MK |
155 | The |
156 | .BR asctime_r () | |
157 | function does the same, but stores the string in | |
ef38dda0 | 158 | a user-supplied buffer which should have room for at least 26 bytes. |
fea681da | 159 | .PP |
60a90ecd MK |
160 | The |
161 | .BR mktime () | |
162 | function converts a broken-down time structure, expressed | |
c13182ef MK |
163 | as local time, to calendar time representation. |
164 | The function ignores | |
9ef659a9 MK |
165 | the values supplied by the caller in the |
166 | .I tm_wday | |
167 | and | |
168 | .I tm_yday | |
169 | fields. | |
f9db4400 MK |
170 | The value specified in the |
171 | .I tm_isdst | |
172 | field informs | |
173 | .BR mktime () | |
174 | whether or not daylight saving time (DST) | |
175 | is in effect for the time supplied in the | |
176 | .I tm | |
177 | structure: | |
178 | a positive value means DST is in effect; | |
179 | zero means that DST is not in effect; | |
180 | and a negative value means that | |
9ef659a9 | 181 | .BR mktime () |
f9db4400 MK |
182 | should (use timezone information and system databases to) |
183 | attempt to determine whether DST is in effect at the specified time. | |
847e0d88 | 184 | .PP |
f9db4400 MK |
185 | The |
186 | .BR mktime () | |
187 | function modifies the fields of the | |
1ae6b2c7 | 188 | .I tm |
9ef659a9 MK |
189 | structure as follows: |
190 | .I tm_wday | |
191 | and | |
192 | .I tm_yday | |
193 | are set to values determined from the contents of the other fields; | |
194 | if structure members are outside their valid interval, they will be | |
f9db4400 MK |
195 | normalized (so that, for example, 40 October is changed into 9 November); |
196 | .I tm_isdst | |
197 | is set (regardless of its initial value) | |
198 | to a positive value or to 0, respectively, | |
acddbaea | 199 | to indicate whether DST is or is not in effect at the specified time. |
60a90ecd MK |
200 | Calling |
201 | .BR mktime () | |
202 | also sets the external variable \fItzname\fP with | |
5b0dc1ba | 203 | information about the current timezone. |
847e0d88 | 204 | .PP |
c13182ef | 205 | If the specified broken-down |
be9634cf | 206 | time cannot be represented as calendar time (seconds since the Epoch), |
60a90ecd | 207 | .BR mktime () |
ab3206e7 | 208 | returns |
009df872 | 209 | .I (time_t)\ \-1 |
7d2cb9d5 | 210 | and does not alter the |
f9db4400 | 211 | members of the broken-down time structure. |
47297adb | 212 | .SH RETURN VALUE |
f5633e8d MK |
213 | On success, |
214 | .BR gmtime () | |
215 | and | |
216 | .BR localtime () | |
217 | return a pointer to a | |
218 | .IR "struct\ tm" . | |
847e0d88 | 219 | .PP |
f5633e8d MK |
220 | On success, |
221 | .BR gmtime_r () | |
222 | and | |
223 | .BR localtime_r () | |
224 | return the address of the structure pointed to by | |
225 | .IR result . | |
847e0d88 | 226 | .PP |
f5633e8d MK |
227 | On success, |
228 | .BR asctime () | |
229 | and | |
230 | .BR ctime () | |
231 | return a pointer to a string. | |
847e0d88 | 232 | .PP |
f5633e8d MK |
233 | On success, |
234 | .BR asctime_r () | |
235 | and | |
236 | .BR ctime_r () | |
237 | return a pointer to the string pointed to by | |
238 | .IR buf . | |
847e0d88 | 239 | .PP |
f5633e8d MK |
240 | On success, |
241 | .BR mktime () | |
d957e9a4 MK |
242 | returns the calendar time (seconds since the Epoch), |
243 | expressed as a value of type | |
f5633e8d | 244 | .IR time_t . |
847e0d88 | 245 | .PP |
f5633e8d MK |
246 | On error, |
247 | .BR mktime () | |
248 | returns the value | |
0a23e9aa | 249 | .IR "(time_t)\ \-1" . |
f5633e8d MK |
250 | The remaining functions return NULL on error. |
251 | On error, | |
252 | .I errno | |
855d489a | 253 | is set to indicate the error. |
d957e9a4 MK |
254 | .SH ERRORS |
255 | .TP | |
256 | .B EOVERFLOW | |
1b9d5819 | 257 | The result cannot be represented. |
c8b68136 ZL |
258 | .SH ATTRIBUTES |
259 | For an explanation of the terms used in this section, see | |
260 | .BR attributes (7). | |
74714ea8 | 261 | .ad l |
c466875e | 262 | .nh |
c8b68136 ZL |
263 | .TS |
264 | allbox; | |
b32feea5 | 265 | lb lb lbx |
c8b68136 ZL |
266 | l l l. |
267 | Interface Attribute Value | |
268 | T{ | |
269 | .BR asctime () | |
b32feea5 MK |
270 | T} Thread safety T{ |
271 | MT-Unsafe race:asctime locale | |
272 | T} | |
c8b68136 ZL |
273 | T{ |
274 | .BR asctime_r () | |
b32feea5 MK |
275 | T} Thread safety T{ |
276 | MT-Safe locale | |
277 | T} | |
c8b68136 ZL |
278 | T{ |
279 | .BR ctime () | |
280 | T} Thread safety T{ | |
281 | MT-Unsafe race:tmbuf | |
c8b68136 ZL |
282 | race:asctime env locale |
283 | T} | |
284 | T{ | |
285 | .BR ctime_r (), | |
286 | .BR gmtime_r (), | |
287 | .BR localtime_r (), | |
288 | .BR mktime () | |
b32feea5 MK |
289 | T} Thread safety T{ |
290 | MT-Safe env locale | |
291 | T} | |
c8b68136 ZL |
292 | T{ |
293 | .BR gmtime (), | |
294 | .BR localtime () | |
b32feea5 MK |
295 | T} Thread safety T{ |
296 | MT-Unsafe race:tmbuf env locale | |
297 | T} | |
c8b68136 | 298 | .TE |
c466875e | 299 | .hy |
74714ea8 | 300 | .ad |
c466875e | 301 | .sp 1 |
3113c7f3 | 302 | .SH STANDARDS |
2b2581ee MK |
303 | POSIX.1-2001. |
304 | C89 and C99 specify | |
305 | .BR asctime (), | |
306 | .BR ctime (), | |
307 | .BR gmtime (), | |
308 | .BR localtime (), | |
309 | and | |
44a2c328 | 310 | .BR mktime (). |
ca5711a5 MK |
311 | POSIX.1-2008 marks |
312 | .BR asctime (), | |
313 | .BR asctime_r (), | |
314 | .BR ctime (), | |
315 | and | |
316 | .BR ctime_r () | |
9e36b352 MK |
317 | as obsolete, |
318 | recommending the use of | |
319 | .BR strftime (3) | |
320 | instead. | |
0300d62f AC |
321 | .PP |
322 | POSIX doesn't specify the parameters of | |
323 | .BR ctime_r () | |
324 | to be | |
325 | .IR restrict ; | |
326 | that is specific to glibc. | |
fea681da MK |
327 | .SH NOTES |
328 | The four functions | |
63aa9df0 MK |
329 | .BR asctime (), |
330 | .BR ctime (), | |
d556548b | 331 | .BR gmtime (), |
fea681da | 332 | and |
63aa9df0 | 333 | .BR localtime () |
fea681da | 334 | return a pointer to static data and hence are not thread-safe. |
800a076a | 335 | The thread-safe versions, |
63aa9df0 MK |
336 | .BR asctime_r (), |
337 | .BR ctime_r (), | |
d556548b | 338 | .BR gmtime_r (), |
fea681da | 339 | and |
800a076a MK |
340 | .BR localtime_r (), |
341 | are specified by SUSv2. | |
847e0d88 | 342 | .PP |
8167059b MK |
343 | POSIX.1-2001 says: |
344 | "The | |
345 | .BR asctime (), | |
346 | .BR ctime (), | |
347 | .BR gmtime (), | |
348 | and | |
349 | .BR localtime () | |
350 | functions shall return values in one of two static objects: | |
351 | a broken-down time structure and an array of type | |
352 | .IR char . | |
353 | Execution of any of the functions may overwrite the information returned | |
354 | in either of these objects by any of the other functions." | |
355 | This can occur in the glibc implementation. | |
dd3568a1 | 356 | .PP |
8167059b | 357 | In many implementations, including glibc, a 0 in |
3e53c142 MK |
358 | .I tm_mday |
359 | is interpreted as meaning the last day of the preceding month. | |
dd3568a1 | 360 | .PP |
259ce44e | 361 | According to POSIX.1-2001, |
7b16ff49 MK |
362 | .BR localtime () |
363 | is required to behave as though | |
0b80cf56 | 364 | .BR tzset (3) |
7b16ff49 MK |
365 | was called, while |
366 | .BR localtime_r () | |
367 | does not have this requirement. | |
368 | .\" See http://thread.gmane.org/gmane.comp.time.tz/2034/ | |
68fc27f7 | 369 | For portable code, |
0b80cf56 | 370 | .BR tzset (3) |
7b16ff49 MK |
371 | should be called before |
372 | .BR localtime_r (). | |
47297adb | 373 | .SH SEE ALSO |
fea681da MK |
374 | .BR date (1), |
375 | .BR gettimeofday (2), | |
376 | .BR time (2), | |
377 | .BR utime (2), | |
378 | .BR clock (3), | |
379 | .BR difftime (3), | |
fea681da MK |
380 | .BR strftime (3), |
381 | .BR strptime (3), | |
7877f012 | 382 | .BR timegm (3), |
eafd5ce1 MK |
383 | .BR tzset (3), |
384 | .BR time (7) |