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 .\" 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.
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
30 .\" From: @(#)ctime.3 8.1 (Berkeley) 6/4/93
31 .\" $FreeBSD: src/lib/libc/stdtime/ctime.3,v 1.24 2007/01/09 00:28:11 imp Exp $
49 .Nd transform binary date and time values
54 .Vt extern char *tzname[2] ;
56 .Fn asctime "const struct tm *timeptr"
58 .Fn asctime_r "const struct tm *restrict timeptr" "char *restrict buf"
60 .Fn ctime "const time_t *clock"
62 .Fn ctime_r "const time_t *clock" "char *buf"
64 .Fn difftime "time_t time1" "time_t time0"
66 .Fn gmtime "const time_t *clock"
68 .Fn gmtime_r "const time_t *clock" "struct tm *result"
70 .Fn localtime "const time_t *clock"
72 .Fn localtime_r "const time_t *clock" "struct tm *result"
74 .Fn mktime "struct tm *timeptr"
76 .Fn timegm "struct tm *timeptr"
78 .Fn timelocal "struct tm *timeptr"
85 all take as an argument a time value representing the time in seconds since
90 When encountering an error, these functions return
94 to an appropriate value.
98 converts the time value pointed at by
100 It returns a pointer to a
102 (described below), which contains
103 the broken-out time information for the value after adjusting for the current
104 time zone (and any other factors such as Daylight Saving Time).
105 Time zone adjustments are performed as specified by the
107 environment variable (see
113 to initialize time conversion information, if
115 has not already been called by the process.
117 After filling in the tm structure,
125 string containing the time zone abbreviation to be
132 also converts the time value, but makes no time zone adjustment.
133 It returns a pointer to a tm structure (described below).
138 adjusts the time value for the current time zone, in the same manner as
140 It returns a pointer to a 26-character string of the form:
141 .Bd -literal -offset indent
142 Thu Nov 24 18:22:48 1986\en\e0
145 All of the fields have constant width.
150 provides the same functionality as
152 except that the caller must provide the output buffer
154 (which must be at least 26 characters long) to store the result.
160 provide the same functionality as
164 respectively, except the caller must provide the output buffer
170 converts the broken-out time in the structure
175 shown in the example above.
180 provides the same functionality as
182 except that the caller provides the output buffer
184 (which must be at least 26 characters long) to store the result.
190 convert the broken-out time
191 (in the structure pointed to by
193 into a time value with the same encoding as that of the
194 values returned by the
196 function (that is, seconds from the Epoch,
201 interprets the input structure according to the current timezone setting
206 function interprets the input structure
207 as representing Universal Coordinated Time
214 but uses the current timezone setting.
220 The original values of the
224 components of the structure are ignored. The original values of the
225 other components are not restricted to their normal ranges and will be
226 normalized, if need be.
228 October 40 is changed into November 9,
231 of \-1 means 1 hour before midnight,
233 of 0 means the day preceding the current month, and
235 of \-2 means 2 months before January of
237 (A positive or zero value for
241 to presume initially that summer time (for example, Daylight Saving Time)
242 is or is not (respectively) in effect for the specified time.
247 function to attempt to divine whether summer time is in effect for the
253 members are forced to zero by
256 On successful completion, the values of the
260 components of the structure are set appropriately, and the other components
261 are set to represent the specified calendar time, but with their values
262 forced to their normal ranges; the final value of
272 returns the specified calendar time; if the calendar time cannot be
273 represented, it returns \-1;
278 returns the difference between two calendar times,
282 expressed in seconds.
284 External declarations, as well as the tm structure definition,
288 The tm structure includes at least the following fields:
289 .Bd -literal -offset indent
290 int tm_sec; /\(** seconds (0 - 60) \(**/
291 int tm_min; /\(** minutes (0 - 59) \(**/
292 int tm_hour; /\(** hours (0 - 23) \(**/
293 int tm_mday; /\(** day of month (1 - 31) \(**/
294 int tm_mon; /\(** month of year (0 - 11) \(**/
295 int tm_year; /\(** year \- 1900 \(**/
296 int tm_wday; /\(** day of week (Sunday = 0) \(**/
297 int tm_yday; /\(** day of year (0 - 365) \(**/
298 int tm_isdst; /\(** is summer time in effect? \(**/
299 char \(**tm_zone; /\(** abbreviation of timezone name \(**/
300 long tm_gmtoff; /\(** offset from UTC in seconds \(**/
306 is non-zero if summer (i.e., Daylight Saving) time is in effect.
310 is the offset (in seconds) of the time represented from
313 values indicating locations east of the Prime Meridian.
334 provided the selected local timezone does not contain a leap-second table
344 functions are expected to conform to
346 (again provided the selected local timezone does not contain a leap-second
351 function is not specified by any standard; its function cannot be
352 completely emulated using the standard functions described above.
354 This manual page is derived from
355 the time package contributed to Berkeley by
357 and which appeared in
365 variants of the other functions,
366 these functions leaves their result in an internal static object and return
367 a pointer to that object.
368 Subsequent calls to these
369 function will modify the same object.
371 The C Standard provides no mechanism for a program to modify its current
372 local timezone setting, and the
373 .Tn POSIX Ns No \&-standard
374 method is not reentrant.
375 (However, thread-safe implementations are provided
378 threaded environment.)
384 structure points to a static array of characters,
385 which will also be overwritten by any subsequent calls (as well as by
391 Use of the external variable
395 entry in the tm structure is preferred.