]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/ctime.3
Convert function formatting of the form "\fBname\fP()" to ".BR name ()".
[thirdparty/man-pages.git] / man3 / ctime.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\" 386BSD man pages
27 .\" Modified Sat Jul 24 19:49:27 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified Fri Apr 26 12:38:55 MET DST 1996 by Martin Schulze (joey@linux.de)
29 .\" Modified 2001-11-13, aeb
30 .\" Modified 2001-12-13, joey, aeb
31 .\" Modified 2004-11-16, mtk
32 .\"
33 .TH CTIME 3 2004-11-16 "" "Linux Programmer's Manual"
34 .SH NAME
35 asctime, ctime, gmtime, localtime, mktime, asctime_r, ctime_r, gmtime_r,
36 localtime_r \- transform date and time to broken-down time or ASCII
37 .SH SYNOPSIS
38 .nf
39 .B #include <time.h>
40 .sp
41 .BI "char *asctime(const struct tm *" tm );
42 .br
43 .BI "char *asctime_r(const struct tm *" tm ", char *" buf );
44 .sp
45 .BI "char *ctime(const time_t *" timep );
46 .br
47 .BI "char *ctime_r(const time_t *" timep ", char *" buf );
48 .sp
49 .BI "struct tm *gmtime(const time_t *" timep );
50 .br
51 .BI "struct tm *gmtime_r(const time_t *" timep ", struct tm *" result );
52 .sp
53 .BI "struct tm *localtime(const time_t *" timep );
54 .br
55 .BI "struct tm *localtime_r(const time_t *" timep ", struct tm *" result );
56 .sp
57 .BI "time_t mktime(struct tm *" tm );
58 .fi
59 .SH DESCRIPTION
60 The
61 .BR ctime (),
62 .BR gmtime ()
63 and
64 .BR localtime ()
65 functions all take
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 00:00:00 on January 1, 1970, Coordinated Universal
69 Time (UTC).
70 .PP
71 The
72 .BR asctime ()
73 and
74 .BR mktime ()
75 functions both take an argument
76 representing broken-down time which is a representation
77 separated into year, month, day, etc.
78 .PP
79 Broken-down time is stored
80 in the structure \fItm\fP which is defined in \fI<time.h>\fP as follows:
81 .sp
82 .RS
83 .nf
84 struct tm {
85 int tm_sec; /* seconds */
86 int tm_min; /* minutes */
87 int tm_hour; /* hours */
88 int tm_mday; /* day of the month */
89 int tm_mon; /* month */
90 int tm_year; /* year */
91 int tm_wday; /* day of the week */
92 int tm_yday; /* day in the year */
93 int tm_isdst; /* daylight saving time */
94 };
95 .fi
96 .RE
97 .PP
98 The members of the \fItm\fP structure are:
99 .TP
100 .I tm_sec
101 The number of seconds after the minute, normally in the range 0 to 59,
102 but can be up to 60 to allow for leap seconds.
103 .TP
104 .I tm_min
105 The number of minutes after the hour, in the range 0 to 59.
106 .TP
107 .I tm_hour
108 The number of hours past midnight, in the range 0 to 23.
109 .TP
110 .I tm_mday
111 The day of the month, in the range 1 to 31.
112 .TP
113 .I tm_mon
114 The number of months since January, in the range 0 to 11.
115 .TP
116 .I tm_year
117 The number of years since 1900.
118 .TP
119 .I tm_wday
120 The number of days since Sunday, in the range 0 to 6.
121 .TP
122 .I tm_yday
123 The number of days since January 1, in the range 0 to 365.
124 .TP
125 .I tm_isdst
126 A flag that indicates whether daylight saving time is in effect at the
127 time described.
128 The value is positive if daylight saving time is in
129 effect, zero if it is not, and negative if the information is not
130 available.
131 .PP
132 The call
133 .BI ctime( t )
134 is equivalent to
135 .BI asctime(localtime( t )) \fR.
136 It converts the calendar time \fIt\fP into a string of the form
137 .sp
138 .RS
139 "Wed Jun 30 21:49:08 1993\\n"
140 .RE
141 .sp
142 The abbreviations for the days of the week are `Sun', `Mon', `Tue', `Wed',
143 `Thu', `Fri', and `Sat'.
144 The abbreviations for the months are `Jan',
145 `Feb', `Mar', `Apr', `May', `Jun', `Jul', `Aug', `Sep', `Oct', `Nov', and
146 `Dec'.
147 The return value points to a statically allocated string which
148 might be overwritten by subsequent calls to any of the date and time
149 functions.
150 The function also sets the external variable \fItzname\fP (see
151 .BR tzset (3))
152 with information about the current time zone.
153 The re-entrant version
154 .BR ctime_r ()
155 does the same, but stores the
156 string in a user-supplied buffer of length at least 26.
157 It need not
158 set \fItzname\fP.
159 .PP
160 The
161 .BR gmtime ()
162 function converts the calendar time \fItimep\fP to
163 broken-down time representation, expressed in Coordinated Universal Time
164 (UTC).
165 It may return NULL when the year does not fit into an integer.
166 The return value points to a statically allocated struct which might be
167 overwritten by subsequent calls to any of the date and time functions.
168 The
169 .BR gmtime_r ()
170 function does the same, but stores the data in a
171 user-supplied struct.
172 .PP
173 The
174 .BR localtime ()
175 function converts the calendar time \fItimep\fP to
176 broken-time representation, expressed relative to the user's specified
177 time zone.
178 The function acts as if it called
179 .BR tzset (3)
180 and sets the external variables \fItzname\fP with
181 information about the current time zone, \fItimezone\fP with the difference
182 between Coordinated Universal Time (UTC) and local standard time in
183 seconds, and \fIdaylight\fP to a non-zero value if daylight savings
184 time rules apply during some part of the year.
185 The return value points to a statically allocated struct which might be
186 overwritten by subsequent calls to any of the date and time functions.
187 The
188 .BR localtime_r ()
189 function does the same, but stores the data in a
190 user-supplied struct.
191 It need not set \fItzname\fP.
192 .PP
193 The
194 .BR asctime ()
195 function converts the broken-down time value
196 \fItm\fP into a string with the same format as
197 .BR ctime ().
198 The return value points to a statically allocated string which might be
199 overwritten by subsequent calls to any of the date and time functions.
200 The
201 .BR asctime_r ()
202 function does the same, but stores the string in
203 a user-supplied buffer of length at least 26.
204 .PP
205 The
206 .BR mktime ()
207 function converts a broken-down time structure, expressed
208 as local time, to calendar time representation.
209 The function ignores
210 the specified contents of the structure members \fItm_wday\fP and \fItm_yday\fP
211 and recomputes them from the other information in the broken-down time
212 structure.
213 If structure members are outside their legal interval, they will be
214 normalized (so that, e.g., 40 October is changed into 9 November).
215 Calling
216 .BR mktime ()
217 also sets the external variable \fItzname\fP with
218 information about the current time zone.
219 If the specified broken-down
220 time cannot be represented as calendar time (seconds since the epoch),
221 .BR mktime ()
222 returns a value of (time_t)(\-1) and does not alter the
223 \fItm_wday\fP and \fItm_yday\fP members of the broken-down time structure.
224 .SH "RETURN VALUE"
225 Each of these functions returns the value described, or NULL
226 (\-1 in case of
227 .BR mktime ())
228 in case an error was detected.
229 .SH NOTES
230 The four functions
231 .BR asctime (),
232 .BR ctime (),
233 .BR gmtime ()
234 and
235 .BR localtime ()
236 return a pointer to static data and hence are not thread-safe.
237 Thread-safe versions
238 .BR asctime_r (),
239 .BR ctime_r (),
240 .BR gmtime_r ()
241 and
242 .BR localtime_r ()
243 are specified by SUSv2, and available since libc 5.2.5.
244 .LP
245 In many implementations, including
246 .IR glibc ,
247 a 0 in
248 .I tm_mday
249 is interpreted as meaning the last day of the preceding month.
250 .LP
251 The glibc version of struct tm has additional fields
252 .sp
253 .RS
254 .nf
255 long tm_gmtoff; /* Seconds east of UTC */
256 const char *tm_zone; /* Timezone abbreviation */
257 .fi
258 .RE
259 .sp
260 defined when _BSD_SOURCE was set before including
261 .IR <time.h> .
262 This is a BSD extension, present in 4.3BSD-Reno.
263 .SH "CONFORMING TO"
264 POSIX.1-2001.
265 C89 and C99 specify
266 .BR asctime (),
267 .BR ctime (),
268 .BR gmtime (),
269 .BR localtime (),
270 and
271 .BR mktime ()
272 .SH "SEE ALSO"
273 .BR date (1),
274 .BR gettimeofday (2),
275 .BR time (2),
276 .BR utime (2),
277 .BR clock (3),
278 .BR difftime (3),
279 .BR strftime (3),
280 .BR strptime (3),
281 .BR tzset (3),
282 .BR time (7)