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. 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: head/contrib/tzcode/stdtime/ctime.3 165903 2007-01-09 00:28:16Z imp $
48 .Nd transform binary date and time values
53 .Vt extern char *tzname[2] ;
55 .Fn ctime "const time_t *clock"
57 .Fn difftime "time_t time1" "time_t time0"
59 .Fn asctime "const struct tm *tm"
61 .Fn localtime "const time_t *clock"
63 .Fn gmtime "const time_t *clock"
65 .Fn mktime "struct tm *tm"
67 .Fn timegm "struct tm *tm"
69 .Fn ctime_r "const time_t *clock" "char *buf"
71 .Fn localtime_r "const time_t *clock" "struct tm *result"
73 .Fn gmtime_r "const time_t *clock" "struct tm *result"
75 .Fn asctime_r "const struct tm *tm" "char *buf"
82 all take as an argument a time value representing the time in seconds since
90 converts the time value pointed at by
92 and returns a pointer to a
94 (described below) which contains
95 the broken-out time information for the value after adjusting for the current
96 time zone (and any other factors such as Daylight Saving Time).
97 Time zone adjustments are performed as specified by the
99 environment variable (see
105 to initialize time conversion information if
107 has not already been called by the process.
109 After filling in the tm structure,
117 string that is the time zone abbreviation to be
124 similarly converts the time value, but without any time zone adjustment,
125 and returns a pointer to a tm structure (described below).
130 adjusts the time value for the current time zone in the same manner as
132 and returns a pointer to a string of the form:
133 .Bd -literal -offset indent
134 Thu Nov 24 18:22:48 1986\en\e0
137 Years requiring fewer than four characters are padded with leading zeroes.
138 For years longer than four characters, the string is of the form
139 .Bd -literal -offset indent
140 Thu Nov 24 18:22:48 81986\en\e0
143 with five spaces before the year.
144 These unusual formats are designed to make it less likely that older
145 software that expects exactly 26 bytes of output will mistakenly output
146 misleading values for out-of-range years.
151 provides the same functionality as
153 except the caller must provide the output buffer
155 to store the result, which must be at least 26 characters long.
161 provide the same functionality as
165 respectively, except the caller must provide the output buffer
171 converts the broken down time in the structure
176 shown in the example above.
181 provides the same functionality as
183 except the caller provide the output buffer
185 to store the result, which must be at least 26 characters long.
191 convert the broken-down time in the structure
192 pointed to by tm into a time value with the same encoding as that of the
193 values returned by the
195 function (that is, seconds from the Epoch,
200 interprets the input structure according to the current timezone setting
206 interprets the input structure as representing Universal Coordinated Time
209 The original values of the
213 components of the structure are ignored, and the original values of the
214 other components are not restricted to their normal ranges, and will be
215 normalized if needed.
217 October 40 is changed into November 9,
220 of \-1 means 1 hour before midnight,
222 of 0 means the day preceding the current month, and
224 of \-2 means 2 months before January of
226 (A positive or zero value for
230 to presume initially that summer time (for example, Daylight Saving Time)
231 is or is not in effect for the specified time, respectively.
236 function to attempt to divine whether summer time is in effect for the
237 specified time; in this case it does not use a consistent
238 rule and may give a different answer when later
239 presented with the same argument.
244 members are forced to zero by
247 On successful completion, the values of the
251 components of the structure are set appropriately, and the other components
252 are set to represent the specified calendar time, but with their values
253 forced to their normal ranges; the final value of
263 returns the specified calendar time; if the calendar time cannot be
264 represented, it returns \-1;
269 returns the difference between two calendar times,
273 expressed in seconds.
275 External declarations as well as the tm structure definition are in the
278 The tm structure includes at least the following fields:
279 .Bd -literal -offset indent
280 int tm_sec; /\(** seconds (0 - 60) \(**/
281 int tm_min; /\(** minutes (0 - 59) \(**/
282 int tm_hour; /\(** hours (0 - 23) \(**/
283 int tm_mday; /\(** day of month (1 - 31) \(**/
284 int tm_mon; /\(** month of year (0 - 11) \(**/
285 int tm_year; /\(** year \- 1900 \(**/
286 int tm_wday; /\(** day of week (Sunday = 0) \(**/
287 int tm_yday; /\(** day of year (0 - 365) \(**/
288 int tm_isdst; /\(** is summer time in effect? \(**/
289 char \(**tm_zone; /\(** abbreviation of timezone name \(**/
290 long tm_gmtoff; /\(** offset from UT in seconds \(**/
296 is non-zero if summer time is in effect.
300 is the offset (in seconds) of the time represented from
303 values indicating east of the Prime Meridian.
304 The field's name is derived from Greenwich Mean Time, a precursor of UT.
311 behave strangely for years before 1000 or after 9999.
312 The 1989 and 1999 editions of the C Standard say
313 that years from -99 through 999 are converted without
314 extra spaces, but this conflicts with longstanding
315 tradition and with this implementation.
316 Traditional implementations of these two functions are
317 restricted to years in the range 1900 through 2099.
318 To avoid this portability mess, new programs should use
342 provided the selected local timezone does not contain a leap-second table
352 functions are expected to conform to
354 (again provided the selected local timezone does not contain a leap-second
359 function is not specified by any standard; its function cannot be
360 completely emulated using the standard functions described above.
362 This manual page is derived from
363 the time package contributed to Berkeley by
365 and which appeared in
373 variants of the other functions,
374 these functions leaves their result in an internal static object and return
375 a pointer to that object.
376 Subsequent calls to these
377 function will modify the same object.
379 The C Standard provides no mechanism for a program to modify its current
380 local timezone setting, and the
381 .Tn POSIX Ns No \&-standard
382 method is not reentrant.
383 (However, thread-safe implementations are provided
386 threaded environment.)
392 structure points to a static array of characters,
393 which will also be overwritten by any subsequent calls (as well as by
399 Use of the external variable
403 entry in the tm structure is preferred.