]>
Commit | Line | Data |
---|---|---|
5b2abdfb A |
1 | .\" Copyright (c) 1989, 1991, 1993 |
2 | .\" The Regents of the University of California. All rights reserved. | |
3 | .\" | |
4 | .\" This code is derived from software contributed to Berkeley by | |
5 | .\" Arthur Olson. | |
6 | .\" Redistribution and use in source and binary forms, with or without | |
7 | .\" modification, are permitted provided that the following conditions | |
8 | .\" are met: | |
9 | .\" 1. Redistributions of source code must retain the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer. | |
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer in the | |
13 | .\" documentation and/or other materials provided with the distribution. | |
14 | .\" 3. All advertising materials mentioning features or use of this software | |
15 | .\" must display the following acknowledgement: | |
16 | .\" This product includes software developed by the University of | |
17 | .\" California, Berkeley and its contributors. | |
18 | .\" 4. Neither the name of the University nor the names of its contributors | |
19 | .\" may be used to endorse or promote products derived from this software | |
20 | .\" without specific prior written permission. | |
21 | .\" | |
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | .\" SUCH DAMAGE. | |
33 | .\" | |
34 | .\" From: @(#)ctime.3 8.1 (Berkeley) 6/4/93 | |
3d9156a7 | 35 | .\" $FreeBSD: src/lib/libc/stdtime/ctime.3,v 1.22 2004/07/02 23:52:12 ru Exp $ |
5b2abdfb A |
36 | .\" |
37 | .Dd January 2, 1999 | |
38 | .Dt CTIME 3 | |
39 | .Os | |
40 | .Sh NAME | |
41 | .Nm asctime , | |
42 | .Nm asctime_r , | |
43 | .Nm ctime , | |
44 | .Nm ctime_r , | |
45 | .Nm difftime , | |
46 | .Nm gmtime , | |
47 | .Nm gmtime_r , | |
48 | .Nm localtime , | |
49 | .Nm localtime_r , | |
50 | .Nm mktime , | |
51 | .Nm timegm | |
52 | .Nd transform binary date and time values | |
53 | .Sh LIBRARY | |
54 | .Lb libc | |
55 | .Sh SYNOPSIS | |
56 | .In time.h | |
57 | .Vt extern char *tzname[2] ; | |
58 | .Ft char * | |
59 | .Fn ctime "const time_t *clock" | |
60 | .Ft double | |
61 | .Fn difftime "time_t time1" "time_t time0" | |
62 | .Ft char * | |
63 | .Fn asctime "const struct tm *tm" | |
64 | .Ft struct tm * | |
65 | .Fn localtime "const time_t *clock" | |
66 | .Ft struct tm * | |
67 | .Fn gmtime "const time_t *clock" | |
68 | .Ft time_t | |
69 | .Fn mktime "struct tm *tm" | |
70 | .Ft time_t | |
71 | .Fn timegm "struct tm *tm" | |
72 | .Ft char * | |
73 | .Fn ctime_r "const time_t *clock" "char *buf" | |
74 | .Ft struct tm * | |
75 | .Fn localtime_r "const time_t *clock" "struct tm *result" | |
76 | .Ft struct tm * | |
77 | .Fn gmtime_r "const time_t *clock" "struct tm *result" | |
78 | .Ft char * | |
79 | .Fn asctime_r "const struct tm *tm" "char *buf" | |
80 | .Sh DESCRIPTION | |
81 | The functions | |
82 | .Fn ctime , | |
83 | .Fn gmtime | |
84 | and | |
85 | .Fn localtime | |
86 | all take as an argument a time value representing the time in seconds since | |
87 | the Epoch (00:00:00 | |
88 | .Tn UTC , | |
89 | January 1, 1970; see | |
90 | .Xr time 3 ) . | |
91 | .Pp | |
92 | The function | |
93 | .Fn localtime | |
94 | converts the time value pointed at by | |
95 | .Fa clock , | |
96 | and returns a pointer to a | |
97 | .Dq Fa struct tm | |
98 | (described below) which contains | |
99 | the broken-out time information for the value after adjusting for the current | |
100 | time zone (and any other factors such as Daylight Saving Time). | |
101 | Time zone adjustments are performed as specified by the | |
102 | .Ev TZ | |
103 | environment variable (see | |
104 | .Xr tzset 3 ) . | |
105 | The function | |
106 | .Fn localtime | |
107 | uses | |
108 | .Xr tzset 3 | |
109 | to initialize time conversion information if | |
110 | .Xr tzset 3 | |
111 | has not already been called by the process. | |
112 | .Pp | |
113 | After filling in the tm structure, | |
114 | .Fn localtime | |
115 | sets the | |
116 | .Fa tm_isdst Ns 'th | |
117 | element of | |
118 | .Fa tzname | |
119 | to a pointer to an | |
120 | .Tn ASCII | |
121 | string that's the time zone abbreviation to be | |
122 | used with | |
123 | .Fn localtime Ns 's | |
124 | return value. | |
125 | .Pp | |
126 | The function | |
127 | .Fn gmtime | |
128 | similarly converts the time value, but without any time zone adjustment, | |
129 | and returns a pointer to a tm structure (described below). | |
130 | .Pp | |
131 | The | |
132 | .Fn ctime | |
133 | function | |
134 | adjusts the time value for the current time zone in the same manner as | |
135 | .Fn localtime , | |
136 | and returns a pointer to a 26-character string of the form: | |
137 | .Bd -literal -offset indent | |
138 | Thu Nov 24 18:22:48 1986\en\e0 | |
139 | .Ed | |
140 | .Pp | |
141 | All the fields have constant width. | |
142 | .Pp | |
9385eb3d | 143 | The |
5b2abdfb | 144 | .Fn ctime_r |
9385eb3d | 145 | function |
5b2abdfb A |
146 | provides the same functionality as |
147 | .Fn ctime | |
148 | except the caller must provide the output buffer | |
149 | .Fa buf | |
150 | to store the result, which must be at least 26 characters long. | |
9385eb3d | 151 | The |
5b2abdfb A |
152 | .Fn localtime_r |
153 | and | |
154 | .Fn gmtime_r | |
9385eb3d | 155 | functions |
5b2abdfb A |
156 | provide the same functionality as |
157 | .Fn localtime | |
158 | and | |
159 | .Fn gmtime | |
160 | respectively, except the caller must provide the output buffer | |
161 | .Fa result . | |
162 | .Pp | |
163 | The | |
164 | .Fn asctime | |
165 | function | |
166 | converts the broken down time in the structure | |
167 | .Fa tm | |
168 | pointed at by | |
169 | .Fa *tm | |
170 | to the form | |
171 | shown in the example above. | |
172 | .Pp | |
9385eb3d | 173 | The |
5b2abdfb | 174 | .Fn asctime_r |
9385eb3d | 175 | function |
5b2abdfb A |
176 | provides the same functionality as |
177 | .Fn asctime | |
178 | except the caller provide the output buffer | |
179 | .Fa buf | |
180 | to store the result, which must be at least 26 characters long. | |
181 | .Pp | |
182 | The functions | |
183 | .Fn mktime | |
184 | and | |
185 | .Fn timegm | |
186 | convert the broken-down time in the structure | |
187 | pointed to by tm into a time value with the same encoding as that of the | |
188 | values returned by the | |
189 | .Xr time 3 | |
190 | function (that is, seconds from the Epoch, | |
191 | .Tn UTC ) . | |
9385eb3d | 192 | The |
5b2abdfb | 193 | .Fn mktime |
9385eb3d | 194 | function |
5b2abdfb A |
195 | interprets the input structure according to the current timezone setting |
196 | (see | |
197 | .Xr tzset 3 ) . | |
9385eb3d | 198 | The |
5b2abdfb | 199 | .Fn timegm |
9385eb3d | 200 | function |
5b2abdfb A |
201 | interprets the input structure as representing Universal Coordinated Time |
202 | .Pq Tn UTC . | |
203 | .Pp | |
204 | The original values of the | |
205 | .Fa tm_wday | |
206 | and | |
207 | .Fa tm_yday | |
208 | components of the structure are ignored, and the original values of the | |
209 | other components are not restricted to their normal ranges, and will be | |
210 | normalized if needed. | |
211 | For example, | |
212 | October 40 is changed into November 9, | |
213 | a | |
214 | .Fa tm_hour | |
215 | of \-1 means 1 hour before midnight, | |
216 | .Fa tm_mday | |
217 | of 0 means the day preceding the current month, and | |
218 | .Fa tm_mon | |
219 | of \-2 means 2 months before January of | |
220 | .Fa tm_year . | |
221 | (A positive or zero value for | |
222 | .Fa tm_isdst | |
223 | causes | |
224 | .Fn mktime | |
225 | to presume initially that summer time (for example, Daylight Saving Time) | |
226 | is or is not in effect for the specified time, respectively. | |
227 | A negative value for | |
228 | .Fa tm_isdst | |
229 | causes the | |
230 | .Fn mktime | |
231 | function to attempt to divine whether summer time is in effect for the | |
232 | specified time. | |
233 | The | |
234 | .Fa tm_isdst | |
235 | and | |
236 | .Fa tm_gmtoff | |
237 | members are forced to zero by | |
238 | .Fn timegm . ) | |
239 | .Pp | |
240 | On successful completion, the values of the | |
241 | .Fa tm_wday | |
242 | and | |
243 | .Fa tm_yday | |
244 | components of the structure are set appropriately, and the other components | |
245 | are set to represent the specified calendar time, but with their values | |
246 | forced to their normal ranges; the final value of | |
247 | .Fa tm_mday | |
248 | is not set until | |
249 | .Fa tm_mon | |
250 | and | |
251 | .Fa tm_year | |
252 | are determined. | |
9385eb3d A |
253 | The |
254 | .Fn mktime | |
255 | function | |
5b2abdfb A |
256 | returns the specified calendar time; if the calendar time cannot be |
257 | represented, it returns \-1; | |
258 | .Pp | |
259 | The | |
260 | .Fn difftime | |
261 | function | |
262 | returns the difference between two calendar times, | |
263 | .Pf ( Fa time1 | |
264 | - | |
265 | .Fa time0 ) , | |
266 | expressed in seconds. | |
267 | .Pp | |
268 | External declarations as well as the tm structure definition are in the | |
3d9156a7 | 269 | .In time.h |
5b2abdfb A |
270 | include file. |
271 | The tm structure includes at least the following fields: | |
272 | .Bd -literal -offset indent | |
273 | int tm_sec; /\(** seconds (0 - 60) \(**/ | |
274 | int tm_min; /\(** minutes (0 - 59) \(**/ | |
275 | int tm_hour; /\(** hours (0 - 23) \(**/ | |
276 | int tm_mday; /\(** day of month (1 - 31) \(**/ | |
277 | int tm_mon; /\(** month of year (0 - 11) \(**/ | |
278 | int tm_year; /\(** year \- 1900 \(**/ | |
279 | int tm_wday; /\(** day of week (Sunday = 0) \(**/ | |
280 | int tm_yday; /\(** day of year (0 - 365) \(**/ | |
281 | int tm_isdst; /\(** is summer time in effect? \(**/ | |
282 | char \(**tm_zone; /\(** abbreviation of timezone name \(**/ | |
283 | long tm_gmtoff; /\(** offset from UTC in seconds \(**/ | |
284 | .Ed | |
285 | .Pp | |
286 | The | |
287 | field | |
288 | .Fa tm_isdst | |
289 | is non-zero if summer time is in effect. | |
290 | .Pp | |
291 | The field | |
292 | .Fa tm_gmtoff | |
293 | is the offset (in seconds) of the time represented from | |
294 | .Tn UTC , | |
295 | with positive | |
296 | values indicating east of the Prime Meridian. | |
297 | .Sh SEE ALSO | |
298 | .Xr date 1 , | |
299 | .Xr gettimeofday 2 , | |
300 | .Xr getenv 3 , | |
301 | .Xr time 3 , | |
302 | .Xr tzset 3 , | |
303 | .Xr tzfile 5 | |
304 | .Sh STANDARDS | |
305 | The | |
306 | .Fn asctime , | |
307 | .Fn ctime , | |
308 | .Fn difftime , | |
309 | .Fn gmtime , | |
310 | .Fn localtime , | |
311 | and | |
312 | .Fn mktime | |
313 | functions conform to | |
314 | .St -isoC , | |
315 | and conform to | |
316 | .St -p1003.1-96 | |
317 | provided the selected local timezone does not contain a leap-second table | |
318 | (see | |
319 | .Xr zic 8 ) . | |
320 | .Pp | |
321 | The | |
322 | .Fn asctime_r , | |
323 | .Fn ctime_r , | |
324 | .Fn gmtime_r , | |
325 | and | |
326 | .Fn localtime_r | |
327 | functions are expected to conform to | |
328 | .St -p1003.1-96 | |
329 | (again provided the selected local timezone does not contain a leap-second | |
330 | table). | |
331 | .Pp | |
332 | The | |
333 | .Fn timegm | |
334 | function is not specified by any standard; its function cannot be | |
335 | completely emulated using the standard functions described above. | |
336 | .Sh HISTORY | |
337 | This manual page is derived from | |
338 | the time package contributed to Berkeley by | |
339 | .An Arthur Olson | |
340 | and which appeared in | |
341 | .Bx 4.3 . | |
342 | .Sh BUGS | |
343 | Except for | |
344 | .Fn difftime , | |
345 | .Fn mktime , | |
346 | and the | |
347 | .Fn \&_r | |
348 | variants of the other functions, | |
349 | these functions leaves their result in an internal static object and return | |
350 | a pointer to that object. | |
351 | Subsequent calls to these | |
352 | function will modify the same object. | |
353 | .Pp | |
354 | The C Standard provides no mechanism for a program to modify its current | |
355 | local timezone setting, and the | |
356 | .Tn POSIX Ns No \&-standard | |
3d9156a7 A |
357 | method is not reentrant. |
358 | (However, thread-safe implementations are provided | |
5b2abdfb A |
359 | in the |
360 | .Tn POSIX | |
361 | threaded environment.) | |
362 | .Pp | |
363 | The | |
9385eb3d A |
364 | .Va tm_zone |
365 | field of a returned | |
366 | .Vt tm | |
367 | structure points to a static array of characters, | |
5b2abdfb A |
368 | which will also be overwritten by any subsequent calls (as well as by |
369 | subsequent calls to | |
370 | .Xr tzset 3 | |
371 | and | |
372 | .Xr tzsetwall 3 ) . | |
373 | .Pp | |
374 | Use of the external variable | |
375 | .Fa tzname | |
376 | is discouraged; the | |
377 | .Fa tm_zone | |
378 | entry in the tm structure is preferred. |