8999 SMBIOS: cleanup 32-bit specific code
[unleashed.git] / usr / src / man / man3c / ctime.3c
blobdb871e73bac69868d0186a986ec3038816a0cb31
1 '\" te
2 .\" Copyright (c) 2005, Sun Microsystems, Inc.  All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved.
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
6 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
8 .\"  This notice shall appear on any product containing this material.
9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
12 .TH CTIME 3C "May 27, 2005"
13 .SH NAME
14 ctime, ctime_r, localtime, localtime_r, gmtime, gmtime_r, asctime, asctime_r,
15 tzset \- convert date and time to string
16 .SH SYNOPSIS
17 .LP
18 .nf
19 #include <time.h>
21 \fBchar *\fR\fBctime\fR(\fBconst time_t *\fR\fIclock\fR);
22 .fi
24 .LP
25 .nf
26 \fBstruct tm *\fR\fBlocaltime\fR(\fBconst time_t *\fR\fIclock\fR);
27 .fi
29 .LP
30 .nf
31 \fBstruct tm *\fR\fBgmtime\fR(\fBconst time_t *\fR\fIclock\fR);
32 .fi
34 .LP
35 .nf
36 \fBchar *\fR\fBasctime\fR(\fBconst struct tm *\fR\fItm\fR);
37 .fi
39 .LP
40 .nf
41 extern time_t timezone, altzone;
42 extern int daylight;
43 extern char *tzname[2];
45 \fBvoid\fR \fBtzset\fR(\fBvoid\fR);
46 .fi
48 .LP
49 .nf
50 \fBchar *\fR\fBctime_r\fR(\fBconst time_t *\fR\fIclock\fR, \fBchar *\fR\fIbuf\fR, \fBint\fR \fIbuflen\fR);
51 .fi
53 .LP
54 .nf
55 \fBstruct tm *\fR\fBlocaltime_r\fR(\fBconst time_t *restrict\fR \fIclock\fR,
56      \fBstruct tm *restrict\fR \fIres\fR);
57 .fi
59 .LP
60 .nf
61 \fBstruct tm *\fR\fBgmtime_r\fR(\fBconst time_t *restrict\fR \fIclock\fR,
62      \fBstruct tm *restrict\fR \fIres\fR);
63 .fi
65 .LP
66 .nf
67 \fBchar *\fR\fBasctime_r\fR(\fBconst struct tm *restrict\fR \fItm\fR, \fBchar *restrict\fR \fIbuf\fR,
68      \fBint\fR \fIbuflen\fR);
69 .fi
71 .SS "Standard conforming"
72 .LP
73 .nf
74 cc [ \fIflag\fR... ] \fIfile\fR... \fB-D_POSIX_PTHREAD_SEMANTICS\fR [ \fIlibrary\fR... ]
76 \fBchar *\fR\fBctime_r\fR(\fBconst time_t *\fR\fIclock\fR, \fBchar *\fR\fIbuf\fR);
77 .fi
79 .LP
80 .nf
81 \fBchar *\fR\fBasctime_r\fR(\fBconst struct tm *\fR\fItm\fR, \fBchar *\fR\fIbuf\fR);
82 .fi
84 .SH DESCRIPTION
85 .sp
86 .LP
87 The \fBctime()\fR function converts the time pointed to by \fIclock\fR,
88 representing the time in seconds since the Epoch (00:00:00 UTC, January 1,
89 1970), to local time in the form of a 26-character string, as shown below. Time
90 zone and daylight savings corrections are made before string generation. The
91 fields are in constant width:
92 .sp
93 .LP
94 Fri Sep 13 00:00:00 1986\en\e0
95 .sp
96 .LP
97 The \fBctime()\fR function is equivalent to:
98 .sp
99 .LP
100 \fBasctime(localtime(\fR\fIclock\fR\fB\fR\fB))\fR
103 The \fBctime()\fR, \fBasctime()\fR, \fBgmtime()\fR, and \fBlocaltime()\fR
104 functions return values in one of two thread-specific data objects: a
105 broken-down time structure and an array of \fBchar\fR. Execution of any of the
106 functions can overwrite the information returned in either of these objects by
107 any of the other functions executed by the same thread.
110 The \fBctime_r()\fR function has the same functionality as \fBctime()\fR except
111 that the caller must supply a buffer \fIbuf\fR with length \fIbuflen\fR to
112 store the result; \fIbuf\fR must be at least 26 bytes. The standard-conforming
113 \fBctime_r()\fR function does not take a \fIbuflen\fR parameter.
116 The \fBlocaltime()\fR and \fBgmtime()\fR functions return pointers to \fBtm\fR
117 structures (see below). The \fBlocaltime()\fR function corrects for the main
118 time zone and possible alternate ("daylight savings") time zone; the
119 \fBgmtime()\fR function converts directly to Coordinated Universal Time (UTC),
120 which is what the UNIX system uses internally.
123 The \fBlocaltime_r()\fR and \fBgmtime_r()\fR functions have the same
124 functionality as \fBlocaltime()\fR and \fBgmtime()\fR respectively, except that
125 the caller must supply a buffer \fIres\fR to store the result.
128 The \fBasctime()\fR function converts a \fBtm\fR structure to a 26-character
129 string, as shown in the previous example, and returns a pointer to the string.
132 The \fBasctime_r()\fR function has the same functionality as \fBasctime()\fR
133 except that the caller must supply a buffer \fIbuf\fR with length \fIbuflen\fR
134 for the result to be stored.  The \fIbuf\fR argument must be at least 26 bytes.
135 The standard-conforming \fBasctime_r()\fR function does not take a \fIbuflen\fR
136 parameter.  The \fBasctime_r()\fR function returns a pointer to \fIbuf\fR upon
137 success.  In case of failure, \fINULL\fR is returned and \fBerrno\fR is set.
140 Declarations of all the functions and externals, and the \fBtm\fR structure,
141 are in the <\fBtime.h\fR> header. The members of the \fBtm\fR structure are:
143 .in +2
145 int   tm_sec;    /* seconds after the minute \(em [0, 60] */
146                  /* for leap seconds */
147 int   tm_min;    /* minutes after the hour \(em [0, 59] */
148 int   tm_hour;   /* hour since midnight \(em [0, 23] */
149 int   tm_mday;   /* day of the month \(em [1, 31] */
150 int   tm_mon;    /* months since January \(em [0, 11] */
151 int   tm_year;   /* years since 1900 */
152 int   tm_wday;   /* days since Sunday \(em [0, 6] */
153 int   tm_yday;   /* days since January 1 \(em [0, 365] */
154 int   tm_isdst;  /* flag for alternate daylight savings time */
156 .in -2
160 The value of \fBtm_isdst\fR is positive if daylight savings time is in effect,
161 zero if daylight savings time is not in effect, and negative if the information
162 is not available. Previously, the value of \fBtm_isdst\fR was defined as
163 non-zero if daylight savings was in effect.
166 The external \fBtime_t\fR variable \fBaltzone\fR contains the difference, in
167 seconds, between Coordinated Universal Time and the alternate time zone. The
168 external variable \fBtimezone\fR contains the difference, in seconds, between
169 UTC and local standard time. The external variable \fBdaylight\fR indicates
170 whether time should reflect daylight savings time. Both \fBtimezone\fR and
171 \fBaltzone\fR default to 0 (UTC). The external variable \fBdaylight\fR is
172 non-zero if an alternate time zone exists. The time zone names are contained in
173 the external variable \fBtzname\fR, which by default is set to:
176 char *tzname[2] = { "GMT", "\|" };
179 These functions know about the peculiarities of this conversion for various
180 time periods for the \fBU.S.\fR (specifically, the years 1974, 1975, and 1987).
181 They start handling the new daylight savings time starting with the first
182 Sunday in April, 1987.
185 The \fBtzset()\fR function uses the contents of the environment variable
186 \fBTZ\fR to override the value of the different external variables. It is
187 called by \fBasctime()\fR and can also be called by the user. If \fBTZ\fR is
188 not specified or has an invalid setting, \fBtzset()\fR uses \fBGMT0\fR. See
189 \fBenviron\fR(5) for a description of the \fBTZ\fR environment variable.
192 Starting and ending times are relative to the current local time zone. If the
193 alternate time zone start and end dates and the time are not provided, the days
194 for the United States that year will be used and the time will be 2 AM. If the
195 start and end dates are provided but the time is not provided, the time will be
196 2 AM. The effects of \fBtzset()\fR change the values of the external variables
197 \fBtimezone\fR, \fBaltzone\fR, \fBdaylight\fR, and \fBtzname\fR.
200 Note that in most installations, \fBTZ\fR is set to the correct value by
201 default when the user logs on, using the local \fB/etc/default/init\fR file
202 (see \fBTIMEZONE\fR(4)).
203 .SH RETURN VALUES
206 Upon successful completion, the \fBgmtime()\fR and \fBlocaltime()\fR functions
207 return a pointer to a \fBstruct tm\fR. If an error is detected, \fBgmtime()\fR
208 and \fBlocaltime()\fR return a null pointer.
211 Upon successful completion, the \fBgmtime_r()\fR and \fBlocaltime_r()\fR
212 functions return the address of the structure pointed to by the \fIres\fR
213 argument. If an error is detected, \fBgmtime_r()\fR and \fBlocaltime_r()\fR
214 return a null pointer and set \fBerrno\fR to indicate the error.
215 .SH ERRORS
218 The \fBctime_r()\fR and \fBasctime_r()\fR functions will fail if:
220 .ne 2
222 \fB\fBERANGE\fR\fR
224 .RS 10n
225 The length of the buffer supplied by the caller is not large enough to store
226 the result.
231 The \fBgmtime()\fR, \fBgmtime_r()\fR, \fBlocaltime()\fR, and
232 \fBlocaltime_r()\fR functions will fail if:
234 .ne 2
236 \fB\fBEOVERFLOW\fR\fR
238 .RS 13n
239 The result cannot be represented.
242 .SH USAGE
245 These functions do not support localized date and time formats. The
246 \fBstrftime\fR(3C) function can be used when localization is required.
249 The \fBlocaltime()\fR, \fBlocaltime_r()\fR, \fBgmtime()\fR, \fBgmtime_r()\fR,
250 \fBctime()\fR, and \fBctime_r()\fR functions assume Gregorian dates. Times
251 before the adoption of the Gregorian calendar will not match historial records.
252 .SH EXAMPLES
254 \fBExample 1 \fRExamples of the \fBtzset()\fR function.
257 The \fBtzset()\fR function scans the contents of the environment variable and
258 assigns the different fields to the respective variable. For example, the most
259 complete setting for New Jersey in 1986 could be:
262 .in +2
264 EST5EDT4,116/2:00:00,298/2:00:00
266 .in -2
270 or simply
273 .in +2
275 EST5EDT
277 .in -2
281 An example of a southern hemisphere setting such as the Cook Islands could be
284 .in +2
286 KDT9:30KST10:00,63/5:00,302/20:00
288 .in -2
292 In the longer version of the New Jersey example of \fBTZ,\fR
293 \fBtzname\fR[\fB0\fR] is EST, \fBtimezone\fR is set to 5*60*60,
294 \fBtzname\fR[\fB1\fR] is EDT, \fBaltzone\fR is set to 4*60*60, the starting
295 date of the alternate time zone is the 117th day at 2 AM, the ending date of
296 the alternate time zone is the 299th day at 2 AM (using zero-based Julian
297 days), and \fBdaylight\fR is set positive. Starting and ending times are
298 relative to the current local time zone. If the alternate time zone start and
299 end dates and the time are not provided, the days for the United States that
300 year will be used and the time will be 2 AM. If the start and end dates are
301 provided but the time is not provided, the time will be 2 AM. The effects of
302 \fBtzset()\fR are thus to change the values of the external variables
303 \fBtimezone\fR, \fBaltzone\fR, \fBdaylight\fR, and \fBtzname\fR. The
304 \fBctime()\fR, \fBlocaltime()\fR, \fBmktime()\fR, and \fBstrftime()\fR
305 functions also update these external variables as if they had called
306 \fBtzset()\fR at the time specified by the \fBtime_t\fR or \fBstruct tm\fR
307 value that they are converting.
309 .SH BUGS
312 The \fBzoneinfo\fR timezone data files do not transition past Tue Jan 19
313 03:14:07 2038 UTC.  Therefore for 64-bit applications using \fBzoneinfo\fR
314 timezones, calculations beyond this date might not use the correct offset from
315 standard time, and could return incorrect values. This affects the 64-bit
316 version of \fBlocaltime()\fR, \fBlocaltime_r()\fR, \fBctime()\fR, and
317 \fBctime_r()\fR.
318 .SH ATTRIBUTES
321 See \fBattributes\fR(5) for descriptions of the following attributes:
326 box;
327 c | c
328 l | l .
329 ATTRIBUTE TYPE  ATTRIBUTE VALUE
331 CSI     Enabled
333 Interface Stability     Standard
335 MT-Level        MT-Safe with exceptions
340 The \fBasctime()\fR, \fBctime()\fR, \fBgmtime()\fR, and \fBlocaltime()\fR
341 functions are safe to use in multithread applications because they employ
342 thread-specific data. However, their use is discouraged because standards do
343 not require them to be thread-safe. The \fBasctime_r()\fR and \fBgmtime_r()\fR
344 functions are MT-Safe. The \fBctime_r()\fR, \fBlocaltime_r()\fR, and
345 \fBtzset()\fR functions are MT-Safe in multithread applications, as long as no
346 user-defined function directly modifies one of the following variables:
347 \fBtimezone\fR, \fBaltzone\fR, \fBdaylight\fR, and \fBtzname\fR. These four
348 variables are not MT-Safe to access. They are modified by the \fBtzset()\fR
349 function in an MT-Safe manner. The \fBmktime()\fR, \fBlocaltime_r()\fR, and
350 \fBctime_r()\fR functions call \fBtzset()\fR.
351 .SH SEE ALSO
354 \fBtime\fR(2), \fBIntro\fR(3), \fBgetenv\fR(3C), \fBmktime\fR(3C),
355 \fBprintf\fR(3C), \fBputenv\fR(3C), \fBsetlocale\fR(3C), \fBstrftime\fR(3C),
356 \fBTIMEZONE\fR(4), \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)
357 .SH NOTES
360 When compiling multithreaded programs, see \fBIntro\fR(3).
363 The return values for \fBasctime()\fR, \fBctime()\fR, \fBgmtime()\fR, and
364 \fBlocaltime()\fR point to thread-specific data whose content is overwritten by
365 each call by the same thread.
368 Setting the time during the interval of change from \fBtimezone\fR to
369 \fBaltzone\fR or vice versa can produce unpredictable results. The system
370 administrator must change the Julian start and end days annually.
373 If \fBtzset()\fR has previously evaluated the timezone identified by the value
374 of the \fBTZ\fR  environment variable, \fBtzset()\fR can reuse the previous
375 settings of the external variables \fBaltzone\fR, \fBdaylight\fR,
376 \fBtimezone\fR, and \fBtzname\fR[] associated with that timezone.
379 Solaris 2.4 and earlier releases provided definitions of the \fBctime_r()\fR,
380 \fBlocaltime_r()\fR, \fBgmtime_r()\fR, and \fBasctime_r()\fR functions as
381 specified in POSIX.1c Draft 6. The final POSIX.1c standard changed the
382 interface for \fBctime_r()\fR and \fBasctime_r()\fR. Support for the Draft 6
383 interface is provided for compatibility only and might not be supported in
384 future releases. New applications and libraries should use the
385 standard-conforming interface.
388 For POSIX.1c-conforming applications, the \fB_POSIX_PTHREAD_SEMANTICS\fR and
389 \fB_REENTRANT\fR flags are automatically turned on by defining the
390 \fB_POSIX_C_SOURCE\fR flag with a value >= 199506L.
393 In Solaris 10, \fBgmtime()\fR, \fBgmtime_r()\fR, \fBlocaltime()\fR, and
394 \fBlocaltime_r()\fR were updated to return a null pointer if an error is
395 detected. This change was based on the SUSv3 specification. See
396 \fBstandards\fR(5).