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