1 .\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
2 .TH "LOCALTIME" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
5 localtime, localtime_r \- convert a time value to a broken-down local
12 struct tm *localtime(const time_t *\fP\fItimer\fP\fB);
16 \fBstruct tm *localtime_r(const time_t *restrict\fP \fItimer\fP\fB,
18 \ \ \ \ \ \ struct tm *restrict\fP \fIresult\fP\fB); \fP
24 For \fIlocaltime\fP(): The functionality described on this reference
25 page is aligned with the ISO\ C standard. Any
26 conflict between the requirements described here and the ISO\ C standard
27 is unintentional. This volume of
28 IEEE\ Std\ 1003.1-2001 defers to the ISO\ C standard.
30 The \fIlocaltime\fP() function shall convert the time in seconds since
31 the Epoch pointed to by \fItimer\fP into a broken-down
32 time, expressed as a local time. The function corrects for the timezone
33 and any seasonal time adjustments. \ Local timezone
34 information is used as though \fIlocaltime\fP() calls \fItzset\fP().
36 The relationship between a time in seconds since the Epoch used as
37 an argument to \fIlocaltime\fP() and the \fBtm\fP structure
38 (defined in the \fI<time.h>\fP header) is that the result shall be
40 expression given in the definition of seconds since the Epoch (see
41 the Base Definitions volume of IEEE\ Std\ 1003.1-2001,
42 Section 4.14, Seconds Since the Epoch) corrected for timezone and
44 time adjustments, where the names in the structure and in the expression
47 The same relationship shall apply for \fIlocaltime_r\fP().
50 \fIlocaltime\fP() function need not be reentrant. A function that
51 is not required to be reentrant is not required to be
54 The \fIasctime\fP(), \fIctime\fP(), \fIgmtime\fP(), and \fIlocaltime\fP()
55 functions shall return values in one of two static objects:
56 a broken-down time structure and an array of type \fBchar\fP. Execution
57 of any of the functions may overwrite the information
58 returned in either of these objects by any of the other functions.
60 The \fIlocaltime_r\fP() function shall convert the time in seconds
61 since the Epoch pointed to by \fItimer\fP into a broken-down
62 time stored in the structure to which \fIresult\fP points. The \fIlocaltime_r\fP()
63 function shall also return a pointer to that
66 Unlike \fIlocaltime\fP(), the reentrant version is not required to
70 Upon successful completion, the \fIlocaltime\fP() function shall return
71 a pointer to the broken-down time structure. If an
72 error is detected, \fIlocaltime\fP() shall return a null pointer
73 \ and set \fIerrno\fP to indicate the error.
75 Upon successful completion, \fIlocaltime_r\fP() shall return a pointer
76 to the structure pointed to by the argument \fIresult\fP.
79 The \fIlocaltime\fP() function shall fail if:
82 The result cannot be represented.
85 \fIThe following sections are informative.\fP
87 .SS Getting the Local Date and Time
89 The following example uses the \fItime\fP() function to calculate
91 seconds, since January 1, 1970 0:00 UTC (the Epoch), \fIlocaltime\fP()
92 to convert that value to a broken-down time, and \fIasctime\fP() to
93 convert the broken-down time values into a printable string.
108 printf("%s%ju secs since the Epoch\\n",
109 asctime(localtime(&result)),
117 This example writes the current time to \fIstdout\fP in a form like
123 \fBWed Jun 26 10:32:15 1996
124 835810335 secs since the Epoch
128 .SS Getting the Modification Time for a File
130 The following example gets the modification time for a file. The \fIlocaltime\fP()
131 function converts the \fBtime_t\fP value of
132 the last modification date, obtained by a previous call to \fIstat\fP(),
134 structure that contains the year, month, day, and so on.
143 tm = localtime(&statbuf.st_mtime);
150 The following example gets the current time, converts it to a string
151 using \fIlocaltime\fP() and \fIasctime\fP(), and prints it to standard
152 output using \fIfputs\fP(). It then prints the number of minutes to
153 an event being timed.
162 int minutes_to_event;
165 printf("The time is ");
166 fputs(asctime(localtime(&now)), stdout);
167 printf("There are still %d minutes to the event.\\n",
173 .SH APPLICATION USAGE
175 The \fIlocaltime_r\fP() function is thread-safe and returns values
176 in a user-supplied buffer instead of possibly using a static
177 data area that may be overwritten by each call.
181 .SH FUTURE DIRECTIONS
186 \fIasctime\fP() , \fIclock\fP() , \fIctime\fP()
187 , \fIdifftime\fP() , \fIgetdate\fP() , \fIgmtime\fP() , \fImktime\fP()
188 , \fIstrftime\fP() , \fIstrptime\fP() , \fItime\fP() , \fIutime\fP()
190 Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI<time.h>\fP
192 Portions of this text are reprinted and reproduced in electronic form
193 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
194 -- Portable Operating System Interface (POSIX), The Open Group Base
195 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
196 Electrical and Electronics Engineers, Inc and The Open Group. In the
197 event of any discrepancy between this version and the original IEEE and
198 The Open Group Standard, the original IEEE and The Open Group Standard
199 is the referee document. The original Standard can be obtained online at
200 http://www.opengroup.org/unix/online.html .