1 .\" $NetBSD: ctime.3,v 1.28 2009/12/31 22:49:16 mlelstv Exp $
16 .Nd convert date and time to ASCII
21 .Dv extern char *tzname[2];
23 .Fn ctime "const time_t *clock"
25 .Fn ctime_r "const time_t *clock" "char *buf"
27 .Fn difftime "time_t time1" "time_t time0"
29 .Fn asctime "const struct tm *tm"
31 .Fn asctime_r "const struct tm restrict tm" "char * restrict buf"
33 .Fn localtime "const time_t *clock"
35 .Fn localtime_r "const time_t * restrict clock" "struct tm * restrict result"
37 .Fn gmtime "const time_t *clock"
39 .Fn gmtime_r "const time_t * restrict clock" "struct tm * restrict result"
41 .Fn mktime "struct tm *tm"
44 converts a long integer, pointed to by
46 representing the time in seconds since
47 00:00:00 UTC, 1970-01-01,
48 and returns a pointer to a
50 .D1 Thu Nov 24 18:22:48 1986\en\e0
51 Years requiring fewer than four characters are padded with leading zeroes.
52 For years longer than four characters, the string is of the form
53 .D1 Thu Nov 24 18:22:48 81986\en\e0
54 with five spaces before the year.
55 These unusual formats are designed to make it less likely that older
56 software that expects exactly 26 bytes of output will mistakenly output
57 misleading values for out-of-range years.
64 structures, described below.
66 corrects for the time zone and any time zone adjustments
67 (such as Daylight Saving Time in the U.S.A.).
72 (such as Daylight Saving Time in the United States).
82 ASCII string that's the time zone abbreviation to be used with
87 converts to Coordinated Universal Time.
93 functions provide the same functionality as
97 differing in that the caller must supply a buffer area
99 in which the result is stored; also,
101 does not imply initialization of the local time conversion information;
102 the application may need to do so by calling
106 converts a time value contained in a
107 ``tm'' structure to a string,
108 as shown in the above example,
109 and returns a pointer to the string.
112 converts the broken-down time,
113 expressed as local time,
114 in the structure pointed to by
116 into a calendar time value with the same encoding as that of the values
120 The original values of the
124 components of the structure are ignored,
125 and the original values of the other components are not restricted
126 to their normal ranges.
127 (A positive or zero value for
131 to presume initially that summer time (for example, Daylight Saving Time
132 in the U.S.A.) respectively,
133 is or is not in effect for the specified time.
138 function to attempt to divine whether summer time is in effect
139 for the specified time; in this case it does not use a consistent
140 rule and may give a different answer when later
141 presented with the same argument.)
142 On successful completion, the values of the
146 components of the structure are set appropriately,
147 and the other components are set to represent the specified calendar time,
148 but with their values forced to their normal ranges; the final value of
156 returns the specified calendar time; if the calendar time cannot be
157 represented, it returns -1.
160 returns the difference between two calendar times,
161 .Fa ( time1 No - Fa time0 ) ,
162 expressed in seconds.
164 The structure (of type)
166 includes the following fields:
167 .Bd -literal -offset indent
168 int tm_sec; /* seconds after the minute [0,61] */
169 int tm_min; /* minutes after the hour [0,59] */
170 int tm_hour; /* hours since midnight [0,23] */
171 int tm_mday; /* day of the month [1,31] */
172 int tm_mon; /* months since January [0,11] */
173 int tm_year; /* years since 1900 */
174 int tm_wday; /* day of week [0,6] (Sunday = 0) */
175 int tm_yday; /* day of year [0,365] (Jan 1 = 0) */
176 int tm_isdst; /* daylight savings flag */
177 long tm_gmtoff; /* offset from UTC in seconds */
178 char *tm_zone; /* abbreviation of timezone name */
185 fields exist, and are filled in, only if arrangements to do
186 so were made when the library containing these functions was
188 There is no guarantee that these fields will continue to exist
189 in this form in future releases of this code.
192 is non-zero if summer time is in effect.
195 is the offset (in seconds) of the time represented
196 from UTC, with positive values indicating east
197 of the Prime Meridian.
199 .Bl -tag -width /usr/share/zoneinfo/posixrules -compact
200 .It Pa /etc/localtime
202 .It Pa /usr/share/zoneinfo
203 time zone information directory
204 .It Pa /usr/share/zoneinfo/posixrules
205 used with POSIX-style TZ's
206 .It Pa /usr/share/zoneinfo/GMT
211 .Pa /usr/share/zoneinfo/GMT
212 is absent, UTC leap seconds are loaded from
213 .Pa /usr/share/zoneinfo/posixrules .
240 The return values point to static data; the data is overwritten by
246 points to a static array of characters, which
247 will also be overwritten at the next call
254 behave strangely for years before 1000 or after 9999.
255 The 1989 and 1999 editions of the C Standard say
256 that years from \-99 through 999 are converted without
257 extra spaces, but this conflicts with longstanding
258 tradition and with this implementation.
259 Traditional implementations of these two functions are
260 restricted to years in the range 1900 through 2099.
261 To avoid this portability mess, new programs should use
265 Avoid using out-of-range values with
267 when setting up lunch with promptness sticklers in Riyadh.
268 .\" @(#)newctime.3 8.3
269 .\" This file is in the public domain, so clarified as of
270 .\" 2009-05-17 by Arthur David Olson.