1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" References consulted:
6 .\" Linux libc source code
7 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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
13 .\" Modified 2004-11-16, mtk
15 .TH CTIME 3 2021-03-22 GNU "Linux Programmer's Manual"
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
21 .RI ( libc ", " \-lc )
26 .BI "char *asctime(const struct tm *" tm );
27 .BI "char *asctime_r(const struct tm *restrict " tm ", char *restrict " buf );
29 .BI "char *ctime(const time_t *" timep );
30 .BI "char *ctime_r(const time_t *restrict " timep ", char *restrict " buf );
32 .BI "struct tm *gmtime(const time_t *" timep );
33 .BI "struct tm *gmtime_r(const time_t *restrict " timep ,
34 .BI " struct tm *restrict " result );
36 .BI "struct tm *localtime(const time_t *" timep );
37 .BI "struct tm *localtime_r(const time_t *restrict " timep ,
38 .BI " struct tm *restrict " result );
40 .BI "time_t mktime(struct tm *" tm );
44 Feature Test Macro Requirements for glibc (see
45 .BR feature_test_macros (7)):
54 || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
63 an argument of data type \fItime_t\fP, which represents calendar time.
64 When interpreted as an absolute time value, it represents the number of
65 seconds elapsed since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
71 functions both take an argument
72 representing broken-down time, which is a representation
73 separated into year, month, day, and so on.
75 Broken-down time is stored
76 in the structure \fItm\fP, which is defined in \fI<time.h>\fP as follows:
81 int tm_sec; /* Seconds (0\-60) */
82 int tm_min; /* Minutes (0\-59) */
83 int tm_hour; /* Hours (0\-23) */
84 int tm_mday; /* Day of the month (1\-31) */
85 int tm_mon; /* Month (0\-11) */
86 int tm_year; /* Year \- 1900 */
87 int tm_wday; /* Day of the week (0\-6, Sunday = 0) */
88 int tm_yday; /* Day in the year (0\-365, 1 Jan = 0) */
89 int tm_isdst; /* Daylight saving time */
94 The members of the \fItm\fP structure are:
97 The number of seconds after the minute, normally in the range 0 to 59,
98 but can be up to 60 to allow for leap seconds.
101 The number of minutes after the hour, in the range 0 to 59.
104 The number of hours past midnight, in the range 0 to 23.
107 The day of the month, in the range 1 to 31.
110 The number of months since January, in the range 0 to 11.
113 The number of years since 1900.
116 The number of days since Sunday, in the range 0 to 6.
119 The number of days since January 1, in the range 0 to 365.
122 A flag that indicates whether daylight saving time is in effect at the
124 The value is positive if daylight saving time is in
125 effect, zero if it is not, and negative if the information is not
131 .BI asctime(localtime( t )) \fR.
132 It converts the calendar time \fIt\fP into a
133 null-terminated string of the form
137 "Wed Jun 30 21:49:08 1993\en"
141 The abbreviations for the days of the week are "Sun", "Mon", "Tue", "Wed",
142 "Thu", "Fri", and "Sat".
143 The abbreviations for the months are "Jan",
144 "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", and
146 The return value points to a statically allocated string which
147 might be overwritten by subsequent calls to any of the date and time
149 The function also sets the external
150 variables \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP (see
152 with information about the current timezone.
153 The reentrant version
155 does the same, but stores the
156 string in a user-supplied buffer
157 which should have room for at least 26 bytes.
159 set \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP.
163 function converts the calendar time \fItimep\fP to
164 broken-down time representation, expressed in Coordinated Universal Time
166 It may return NULL when the year does not fit into an integer.
167 The return value points to a statically allocated struct which might be
168 overwritten by subsequent calls to any of the date and time functions.
171 function does the same, but stores the data in a
172 user-supplied struct.
176 function converts the calendar time \fItimep\fP to
177 broken-down time representation,
178 expressed relative to the user's specified timezone.
179 The function acts as if it called
181 and sets the external variables \fItzname\fP with
182 information about the current timezone, \fItimezone\fP with the difference
183 between Coordinated Universal Time (UTC) and local standard time in
184 seconds, and \fIdaylight\fP to a nonzero value if daylight savings
185 time rules apply during some part of the year.
186 The return value points to a statically allocated struct which might be
187 overwritten by subsequent calls to any of the date and time functions.
190 function does the same, but stores the data in a
191 user-supplied struct.
192 It need not set \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP.
196 function converts the broken-down time value
197 \fItm\fP into a null-terminated string with the same format as
199 The return value points to a statically allocated string which might be
200 overwritten by subsequent calls to any of the date and time functions.
203 function does the same, but stores the string in
204 a user-supplied buffer which should have room for at least 26 bytes.
208 function converts a broken-down time structure, expressed
209 as local time, to calendar time representation.
211 the values supplied by the caller in the
216 The value specified in the
220 whether or not daylight saving time (DST)
221 is in effect for the time supplied in the
224 a positive value means DST is in effect;
225 zero means that DST is not in effect;
226 and a negative value means that
228 should (use timezone information and system databases to)
229 attempt to determine whether DST is in effect at the specified time.
233 function modifies the fields of the
235 structure as follows:
239 are set to values determined from the contents of the other fields;
240 if structure members are outside their valid interval, they will be
241 normalized (so that, for example, 40 October is changed into 9 November);
243 is set (regardless of its initial value)
244 to a positive value or to 0, respectively,
245 to indicate whether DST is or is not in effect at the specified time.
248 also sets the external variable \fItzname\fP with
249 information about the current timezone.
251 If the specified broken-down
252 time cannot be represented as calendar time (seconds since the Epoch),
256 and does not alter the
257 members of the broken-down time structure.
263 return a pointer to a
270 return the address of the structure pointed to by
277 return a pointer to a string.
283 return a pointer to the string pointed to by
288 returns the calendar time (seconds since the Epoch),
289 expressed as a value of type
295 .IR "(time_t)\ \-1" .
296 The remaining functions return NULL on error.
299 is set to indicate the error.
303 The result cannot be represented.
305 For an explanation of the terms used in this section, see
313 Interface Attribute Value
317 MT-Unsafe race:asctime locale
328 race:asctime env locale
342 MT-Unsafe race:tmbuf env locale
364 recommending the use of
368 POSIX doesn't specify the parameters of
372 that is specific to glibc.
380 return a pointer to static data and hence are not thread-safe.
381 The thread-safe versions,
387 are specified by SUSv2.
396 functions shall return values in one of two static objects:
397 a broken-down time structure and an array of type
399 Execution of any of the functions may overwrite the information returned
400 in either of these objects by any of the other functions."
401 This can occur in the glibc implementation.
403 In many implementations, including glibc, a 0 in
405 is interpreted as meaning the last day of the preceding month.
407 The glibc version of \fIstruct tm\fP has additional fields
411 long tm_gmtoff; /* Seconds east of UTC */
412 const char *tm_zone; /* Timezone abbreviation */
418 was set before including
420 This is a BSD extension, present in 4.3BSD-Reno.
422 According to POSIX.1-2001,
424 is required to behave as though
428 does not have this requirement.
429 .\" See http://thread.gmane.org/gmane.comp.time.tz/2034/
432 should be called before
436 .BR gettimeofday (2),