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 .\" @(#)newctime.3 8.2
35 .\" $FreeBSD: src/lib/libc/stdtime/ctime.3,v 1.11.2.7 2003/05/23 23:53:40 keramida Exp $
36 .\" $DragonFly: src/lib/libc/stdtime/ctime.3,v 1.4 2008/10/19 20:15:58 swildner Exp $
53 .Nd transform binary date and time values
58 .Vt extern char *tzname[2] ;
60 .Fn ctime "const time_t *clock"
62 .Fn difftime "time_t time1" "time_t time0"
64 .Fn asctime "const struct tm *tm"
66 .Fn localtime "const time_t *clock"
68 .Fn gmtime "const time_t *clock"
70 .Fn mktime "struct tm *tm"
72 .Fn timegm "struct tm *tm"
74 .Fn ctime_r "const time_t *clock" "char *buf"
76 .Fn localtime_r "const time_t *clock" "struct tm *result"
78 .Fn gmtime_r "const time_t *clock" "struct tm *result"
80 .Fn asctime_r "const struct tm *tm" "char *buf"
87 all take as an argument a time value representing the time in seconds since
95 converts the time value pointed at by
97 and returns a pointer to a
99 (described below) which contains
100 the broken-out time information for the value after adjusting for the current
101 time zone and any time zone adjustments.
102 Time zone adjustments are performed as specified by the
104 environment variable (see
107 After filling in the tm structure,
115 string that's the time zone abbreviation to be
122 similarly converts the time value, but without any time zone adjustment,
123 and returns a pointer to a tm structure (described below).
128 adjusts the time value for the current time zone in the same manner as
130 and returns a pointer to a string of the form:
131 .Bd -literal -offset indent
132 Thu Nov 24 18:22:48 1986\en\e0
135 Years requiring fewer than four characters are padded with leading zeroes.
136 For years longer than four characters, the string is of the form
137 .Bd -literal -offset indent
138 Thu Nov 24 18:22:48 81986\en\e0
141 with five spaces before the year.
142 These unusual formats are designed to make it less likely that older
143 software that expects exactly 26 bytes of output will mistakenly output
144 misleading values for out-of-range years.
149 provides the same functionality as
151 except the caller must provide the output buffer
153 to store the result, which must be at least 26 characters long.
159 provide the same functionality as
163 respectively, except the caller must provide the output buffer
169 converts the broken down time in the structure
174 shown in the example above.
179 provides the same functionality as
181 except the caller provide the output buffer
183 to store the result, which must be at least 26 characters long.
189 convert the broken-down time in the structure
190 pointed to by tm into a time value with the same encoding as that of the
191 values returned by the
193 function (that is, seconds from the Epoch,
198 interprets the input structure according to the current timezone setting
204 interprets the input structure as representing Universal Coordinated Time
207 The original values of the
211 components of the structure are ignored, and the original values of the
212 other components are not restricted to their normal ranges, and will be
213 normalized if needed.
215 October 40 is changed into November 9,
218 of \-1 means 1 hour before midnight,
220 of 0 means the day preceding the current month, and
222 of \-2 means 2 months before January of
224 (A positive or zero value for
228 to presume initially that summer time (for example, Daylight Saving Time)
229 is or is not in effect for the specified time, respectively.
234 function to attempt to divine whether summer time is in effect for the
235 specified time; in this case it does not use a consistent
236 rule and may give a different answer when later
237 presented with the same argument.
242 members are forced to zero by
245 On successful completion, the values of the
249 components of the structure are set appropriately, and the other components
250 are set to represent the specified calendar time, but with their values
251 forced to their normal ranges; the final value of
261 returns the specified calendar time; if the calendar time cannot be
262 represented, it returns \-1;
267 returns the difference between two calendar times,
271 expressed in seconds.
273 External declarations as well as the tm structure definition are in the
276 The tm structure includes at least the following fields:
277 .Bd -literal -offset indent
278 int tm_sec; /\(** seconds (0 - 60) \(**/
279 int tm_min; /\(** minutes (0 - 59) \(**/
280 int tm_hour; /\(** hours (0 - 23) \(**/
281 int tm_mday; /\(** day of month (1 - 31) \(**/
282 int tm_mon; /\(** month of year (0 - 11) \(**/
283 int tm_year; /\(** year \- 1900 \(**/
284 int tm_wday; /\(** day of week (Sunday = 0) \(**/
285 int tm_yday; /\(** day of year (0 - 365) \(**/
286 int tm_isdst; /\(** is summer time in effect? \(**/
287 char \(**tm_zone; /\(** abbreviation of timezone name \(**/
288 long tm_gmtoff; /\(** offset from UTC in seconds \(**/
294 is non-zero if summer time is in effect.
298 is the offset (in seconds) of the time represented from
301 values indicating east of the Prime Meridian.
308 behave strangely for years before 1000 or after 9999.
309 The 1989 and 1999 editions of the C Standard say
310 that years from -99 through 999 are converted without
311 extra spaces, but this conflicts with longstanding
312 tradition and with this implementation.
313 Traditional implementations of these two functions are
314 restricted to years in the range 1900 through 2099.
315 To avoid this portability mess, new programs should use
339 provided the selected local timezone does not contain a leap-second table
349 functions are expected to conform to
351 (again provided the selected local timezone does not contain a leap-second
356 function is not specified by any standard; its function cannot be
357 completely emulated using the standard functions described above.
359 This manual page is derived from
360 the time package contributed to Berkeley by
362 and which appeared in
370 variants of the other functions,
371 these functions leaves their result in an internal static object and return
372 a pointer to that object.
373 Subsequent calls to these
374 function will modify the same object.
376 The C Standard provides no mechanism for a program to modify its current
377 local timezone setting, and the
378 .Tn POSIX Ns No \&-standard
379 method is not reentrant. (However, thread-safe implementations are provided
382 threaded environment.)
388 structure points to a static array of characters,
389 which will also be overwritten by any subsequent calls (as well as by
395 Use of the external variable
399 entry in the tm structure is preferred.