2 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" References consulted:
7 .\" Linux libc source code
8 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
10 .\" Modified Sat Jul 24 19:49:27 1993 by Rik Faith (faith@cs.unc.edu)
11 .\" Modified Fri Apr 26 12:38:55 MET DST 1996 by Martin Schulze (joey@linux.de)
12 .\" Modified 2001-11-13, aeb
13 .\" Modified 2001-12-13, joey, aeb
14 .\" Modified 2004-11-16, mtk
16 .TH ctime 3 (date) "Linux man-pages (unreleased)"
18 asctime, ctime, gmtime, localtime, mktime, asctime_r, ctime_r, gmtime_r,
19 localtime_r \- transform date and time to broken-down time or ASCII
22 .RI ( libc ", " \-lc )
27 .BI "char *asctime(const struct tm *" tm );
28 .BI "char *asctime_r(const struct tm *restrict " tm ,
29 .BI " char " buf "[restrict 26]);"
31 .BI "char *ctime(const time_t *" timep );
32 .BI "char *ctime_r(const time_t *restrict " timep ,
33 .BI " char " buf "[restrict 26]);"
35 .BI "struct tm *gmtime(const time_t *" timep );
36 .BI "struct tm *gmtime_r(const time_t *restrict " timep ,
37 .BI " struct tm *restrict " result );
39 .BI "struct tm *localtime(const time_t *" timep );
40 .BI "struct tm *localtime_r(const time_t *restrict " timep ,
41 .BI " struct tm *restrict " result );
43 .BI "time_t mktime(struct tm *" tm );
47 Feature Test Macro Requirements for glibc (see
48 .BR feature_test_macros (7)):
57 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
66 an argument of data type \fItime_t\fP, which represents calendar time.
67 When interpreted as an absolute time value, it represents the number of
68 seconds elapsed since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
74 functions both take an argument
75 representing broken-down time, which is a representation
76 separated into year, month, day, and so on.
78 Broken-down time is stored in the structure
86 .BI asctime(localtime( t )) \fR.
87 It converts the calendar time \fIt\fP into a
88 null-terminated string of the form
92 "Wed Jun 30 21:49:08 1993\en"
96 The abbreviations for the days of the week are "Sun", "Mon", "Tue", "Wed",
97 "Thu", "Fri", and "Sat".
98 The abbreviations for the months are "Jan",
99 "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", and
101 The return value points to a statically allocated string which
102 might be overwritten by subsequent calls to any of the date and time
104 The function also sets the external
105 variables \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP (see
107 with information about the current timezone.
108 The reentrant version
110 does the same, but stores the
111 string in a user-supplied buffer
112 which should have room for at least 26 bytes.
114 set \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP.
118 function converts the calendar time \fItimep\fP to
119 broken-down time representation, expressed in Coordinated Universal Time
121 It may return NULL when the year does not fit into an integer.
122 The return value points to a statically allocated struct which might be
123 overwritten by subsequent calls to any of the date and time functions.
126 function does the same, but stores the data in a
127 user-supplied struct.
131 function converts the calendar time \fItimep\fP to
132 broken-down time representation,
133 expressed relative to the user's specified timezone.
134 The function acts as if it called
136 and sets the external variables \fItzname\fP with
137 information about the current timezone, \fItimezone\fP with the difference
138 between Coordinated Universal Time (UTC) and local standard time in
139 seconds, and \fIdaylight\fP to a nonzero value if daylight savings
140 time rules apply during some part of the year.
141 The return value points to a statically allocated struct which might be
142 overwritten by subsequent calls to any of the date and time functions.
145 function does the same, but stores the data in a
146 user-supplied struct.
147 It need not set \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP.
151 function converts the broken-down time value
152 \fItm\fP into a null-terminated string with the same format as
154 The return value points to a statically allocated string which might be
155 overwritten by subsequent calls to any of the date and time functions.
158 function does the same, but stores the string in
159 a user-supplied buffer which should have room for at least 26 bytes.
163 function converts a broken-down time structure, expressed
164 as local time, to calendar time representation.
166 the values supplied by the caller in the
171 The value specified in the
175 whether or not daylight saving time (DST)
176 is in effect for the time supplied in the
179 a positive value means DST is in effect;
180 zero means that DST is not in effect;
181 and a negative value means that
183 should (use timezone information and system databases to)
184 attempt to determine whether DST is in effect at the specified time.
188 function modifies the fields of the
190 structure as follows:
194 are set to values determined from the contents of the other fields;
195 if structure members are outside their valid interval, they will be
196 normalized (so that, for example, 40 October is changed into 9 November);
198 is set (regardless of its initial value)
199 to a positive value or to 0, respectively,
200 to indicate whether DST is or is not in effect at the specified time.
203 also sets the external variable \fItzname\fP with
204 information about the current timezone.
206 If the specified broken-down
207 time cannot be represented as calendar time (seconds since the Epoch),
211 and does not alter the
212 members of the broken-down time structure.
218 return a pointer to a
225 return the address of the structure pointed to by
232 return a pointer to a string.
238 return a pointer to the string pointed to by
243 returns the calendar time (seconds since the Epoch),
244 expressed as a value of type
250 .IR "(time_t)\ \-1" .
251 The remaining functions return NULL on error.
254 is set to indicate the error.
258 The result cannot be represented.
260 For an explanation of the terms used in this section, see
268 Interface Attribute Value
272 MT-Unsafe race:asctime locale
283 race:asctime env locale
297 MT-Unsafe race:tmbuf env locale
319 recommending the use of
323 POSIX doesn't specify the parameters of
327 that is specific to glibc.
335 return a pointer to static data and hence are not thread-safe.
336 The thread-safe versions,
342 are specified by SUSv2.
351 functions shall return values in one of two static objects:
352 a broken-down time structure and an array of type
354 Execution of any of the functions may overwrite the information returned
355 in either of these objects by any of the other functions."
356 This can occur in the glibc implementation.
358 In many implementations, including glibc, a 0 in
360 is interpreted as meaning the last day of the preceding month.
362 According to POSIX.1-2001,
364 is required to behave as though
368 does not have this requirement.
369 .\" See http://thread.gmane.org/gmane.comp.time.tz/2034/
372 should be called before
376 .BR gettimeofday (2),