1 .\" Copyright (c) 1989, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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.
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
34 .\" From: @(#)ctime.3 8.1 (Berkeley) 6/4/93
52 .Nd transform binary date and time values
55 .Vt extern char *tzname[2];
57 .Fn ctime "const time_t *clock"
59 .Fn difftime "time_t time1" "time_t time0"
61 .Fn asctime "const struct tm *tm"
63 .Fn localtime "const time_t *clock"
65 .Fn gmtime "const time_t *clock"
67 .Fn mktime "struct tm *tm"
69 .Fn timegm "struct tm *tm"
71 .Fn ctime_r "const time_t *clock" "char *buf"
73 .Fn localtime_r "const time_t *clock" "struct tm *result"
75 .Fn gmtime_r "const time_t *clock" "struct tm *result"
77 .Fn asctime_r "const struct tm *tm" "char *buf"
84 all take as an argument a time value representing the time in seconds since
92 converts the time value pointed at by
94 and returns a pointer to a
96 (described below) which contains
97 the broken-out time information for the value after adjusting for the current
98 time zone (and any other factors such as Daylight Saving Time).
99 Time zone adjustments are performed as specified by the
101 environment variable (see
107 to initialize time conversion information if
109 has not already been called by the process.
111 After filling in the tm structure,
119 string that's the time zone abbreviation to be
126 similarly converts the time value, but without any time zone adjustment,
127 and returns a pointer to a tm structure (described below).
132 adjusts the time value for the current time zone in the same manner as
134 and returns a pointer to a 26-character string of the form:
135 .Bd -literal -offset indent
136 Thu Nov 24 18:22:48 1986\en\e0
139 All the fields have constant width.
142 provides the same functionality as
144 except the caller must provide the output buffer
146 to store the result, which must be at least 26 characters long.
150 provide the same functionality as
154 respectively, except the caller must provide the output buffer
160 converts the broken down time in the structure
165 shown in the example above.
168 provides the same functionality as
170 except the caller provide the output buffer
172 to store the result, which must be at least 26 characters long.
178 convert the broken-down time in the structure
179 pointed to by tm into a time value with the same encoding as that of the
180 values returned by the
182 function (that is, seconds from the Epoch,
185 interprets the input structure according to the current timezone setting
189 interprets the input structure as representing Universal Coordinated Time
192 The original values of the
196 components of the structure are ignored, and the original values of the
197 other components are not restricted to their normal ranges.
198 (A positive or zero value for
202 to presume initially that summer time (for example, Daylight Saving Time)
203 is or is not in effect for the specified time, respectively.
208 function to attempt to divine whether summer time is in effect for the
214 members are forced to zero by
217 On successful completion, the values of the
221 components of the structure are set appropriately, and the other components
222 are set to represent the specified calendar time, but with their values
223 forced to their normal ranges; the final value of
231 returns the specified calendar time; if the calendar time cannot be
232 represented, it returns \-1;
237 returns the difference between two calendar times,
241 expressed in seconds.
243 External declarations as well as the tm structure definition are in the
246 The tm structure includes at least the following fields:
247 .Bd -literal -offset indent
248 int tm_sec; /\(** seconds (0 - 60) \(**/
249 int tm_min; /\(** minutes (0 - 59) \(**/
250 int tm_hour; /\(** hours (0 - 23) \(**/
251 int tm_mday; /\(** day of month (1 - 31) \(**/
252 int tm_mon; /\(** month of year (0 - 11) \(**/
253 int tm_year; /\(** year \- 1900 \(**/
254 int tm_wday; /\(** day of week (Sunday = 0) \(**/
255 int tm_yday; /\(** day of year (0 - 365) \(**/
256 int tm_isdst; /\(** is summer time in effect? \(**/
257 char \(**tm_zone; /\(** abbreviation of timezone name \(**/
258 long tm_gmtoff; /\(** offset from UTC in seconds \(**/
264 is non-zero if summer time is in effect.
268 is the offset (in seconds) of the time represented from
271 values indicating east of the Prime Meridian.
292 provided the selected local timezone does not contain a leap-second table
302 functions are expected to conform to
304 (again provided the selected local timezone does not contain a leap-second
309 function is not specified by any standard; its function cannot be
310 completely emulated using the standard functions described above.
312 This manual page is derived from
313 the time package contributed to Berkeley by
315 and which appeared in
323 variants of the other functions,
324 these functions leaves their result in an internal static object and return
325 a pointer to that object. Subsequent calls to these
326 function will modify the same object.
328 The C Standard provides no mechanism for a program to modify its current
329 local timezone setting, and the
330 .Tn POSIX Ns No \&-standard
331 method is not reentrant. (However, thread-safe implementations are provided
334 threaded environment.)
338 field of a returned tm structure points to a static array of characters,
339 which will also be overwritten by any subsequent calls (as well as by
345 Use of the external variable
349 entry in the tm structure is preferred.