1 .\" $NetBSD: ctime.3,v 1.37 2010/12/17 01:30:50 wiz Exp $
22 .Nd convert date and time to ASCII
27 .Dv extern char *tzname[2];
29 .Fn ctime "const time_t *clock"
31 .Fn ctime_r "const time_t *clock" "char *buf"
33 .Fn ctime_rz "const timezone_t tz" "const time_t *clock" "char *buf"
35 .Fn difftime "time_t time1" "time_t time0"
37 .Fn asctime "const struct tm *tm"
39 .Fn asctime_r "const struct tm restrict tm" "char * restrict buf"
41 .Fn localtime "const time_t *clock"
43 .Fn localtime_r "const time_t * restrict clock" "struct tm * restrict result"
45 .Fn localtime_rz "const timezone_t tz" "const time_t * restrict clock" "struct tm * restrict result"
47 .Fn gmtime "const time_t *clock"
49 .Fn gmtime_r "const time_t * restrict clock" "struct tm * restrict result"
51 .Fn mktime "struct tm *tm"
53 .Fn mktime_z "const timezone_t tz" "struct tm *tm"
55 .Fn tzalloc "const char *zone"
57 .Fn tzgetname "const timezone_t tz" "int isdst"
59 .Fn tzfree "const timezone_t tz"
66 representing the time in seconds since
67 00:00:00 UTC, 1970-01-01,
68 and returns a pointer to a
70 .D1 Thu Nov 24 18:22:48 1986\en\e0
71 Years requiring fewer than four characters are padded with leading zeroes.
72 For years longer than four characters, the string is of the form
73 .D1 Thu Nov 24 18:22:48 81986\en\e0
74 with five spaces before the year.
75 These unusual formats are designed to make it less likely that older
76 software that expects exactly 26 bytes of output will mistakenly output
77 misleading values for out-of-range years.
82 except it places the result of the conversion on the
84 argument which should be 26 or more bytes long, instead of using a global
91 .Ft "const timezone_t"
92 argument, returned by a previous call to
100 structures, described below.
102 corrects for the time zone and any time zone adjustments
103 (such as Daylight Saving Time in the U.S.A.).
113 ASCII string that's the time zone abbreviation to be used with
118 converts to Coordinated Universal Time.
124 functions provide the same functionality as
128 differing in that the caller must supply a buffer area
130 in which the result is stored; also,
132 does not imply initialization of the local time conversion information;
133 the application may need to do so by calling
140 .Ft "const timezone_t"
141 argument, returned by a previous call to
145 converts a time value contained in a
147 structure to a string,
148 as shown in the above example,
149 and returns a pointer to the string.
152 converts the broken-down time,
153 expressed as local time,
154 in the structure pointed to by
156 into a calendar time value with the same encoding as that of the values
160 The original values of the
164 components of the structure are ignored,
165 and the original values of the other components are not restricted
166 to their normal ranges.
167 (A positive or zero value for
171 to presume initially that summer time (for example, Daylight Saving Time
172 in the U.S.A.) respectively,
173 is or is not in effect for the specified time.
178 function to attempt to divine whether summer time is in effect
179 for the specified time; in this case it does not use a consistent
180 rule and may give a different answer when later
181 presented with the same argument.)
182 On successful completion, the values of the
186 components of the structure are set appropriately,
187 and the other components are set to represent the specified calendar time,
188 but with their values forced to their normal ranges; the final value of
196 returns the specified calendar time; if the calendar time cannot be
197 represented, it returns
204 .Ft "const timezone_t"
205 argument, returned by a previous call to
209 returns the difference between two calendar times,
210 .Fa ( time1 No - Fa time0 ) ,
211 expressed in seconds.
214 takes as an argument a timezone name and returns a
216 object suitable to be used in
221 Instead of setting the environment variable
223 and globally changing the behavior of the calling program, one can use
224 multiple timezones at the same time by using separate
230 variants of the functions.
233 returns the name for the given
239 the call is equivalent to
245 the call is equivalent to
251 argument previously returned by
254 The structure (of type)
256 includes the following fields:
257 .Bd -literal -offset indent
258 int tm_sec; /* seconds after the minute [0,61] */
259 int tm_min; /* minutes after the hour [0,59] */
260 int tm_hour; /* hours since midnight [0,23] */
261 int tm_mday; /* day of the month [1,31] */
262 int tm_mon; /* months since January [0,11] */
263 int tm_year; /* years since 1900 */
264 int tm_wday; /* day of week [0,6] (Sunday = 0) */
265 int tm_yday; /* day of year [0,365] (Jan 1 = 0) */
266 int tm_isdst; /* daylight savings flag */
267 long tm_gmtoff; /* offset from UTC in seconds */
268 char *tm_zone; /* abbreviation of timezone name */
275 fields exist, and are filled in, only if arrangements to do
276 so were made when the library containing these functions was
278 There is no guarantee that these fields will continue to exist
279 in this form in future releases of this code.
282 field will become invalid and point to freed storage if the corresponding
287 .Ft "const timezone_t"
289 argument has been freed by
293 is non-zero if summer time is in effect.
296 is the offset (in seconds) of the time represented
297 from UTC, with positive values indicating east
298 of the Prime Meridian.
304 functions return a pointer to a static character buffer, and the
309 function return a pointer to the user-supplied buffer.
310 On failure they all return
312 and no errors are defined for them.
317 functions return a pointer to a statically allocated
324 functions return a pointer to the user-supplied
326 On failure they all return
328 and the global variable
330 is set to indicate the error.
335 function returns the specified time since the Epoch as a
338 If the time cannot be represented, then
344 setting the global variable
346 to indicate the error.
349 function returns a pointer to a
355 to indicate the error.
357 function returns string containing the name of the timezone given in
360 .Bl -tag -width /usr/share/zoneinfo/posixrules -compact
361 .It Pa /etc/localtime
363 .It Pa /usr/share/zoneinfo
364 time zone information directory
365 .It Pa /usr/share/zoneinfo/posixrules
366 used with POSIX-style TZ's
367 .It Pa /usr/share/zoneinfo/GMT
372 .Pa /usr/share/zoneinfo/GMT
373 is absent, UTC leap seconds are loaded from
374 .Pa /usr/share/zoneinfo/posixrules .
389 The result cannot be represented.
391 The result cannot be represented.
394 All functions that return values except their
396 variants, can also return the same errors as
426 The return values point to static data; the data is overwritten by
432 points to a static array of characters, which
433 will also be overwritten at the next call
440 behave strangely for years before 1000 or after 9999.
441 The 1989 and 1999 editions of the C Standard say
442 that years from \-99 through 999 are converted without
443 extra spaces, but this conflicts with longstanding
444 tradition and with this implementation.
445 Traditional implementations of these two functions are
446 restricted to years in the range 1900 through 2099.
447 To avoid this portability mess, new programs should use
451 Avoid using out-of-range values with
453 when setting up lunch with promptness sticklers in Riyadh.
454 .\" @(#)newctime.3 8.3
455 .\" This file is in the public domain, so clarified as of
456 .\" 2009-05-17 by Arthur David Olson.