]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3p/localtime.3p
Import of man-pages 1.70
[thirdparty/man-pages.git] / man3p / localtime.3p
1 .\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
2 .TH "LOCALTIME" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
3 .\" localtime
4 .SH NAME
5 localtime, localtime_r \- convert a time value to a broken-down local
6 time
7 .SH SYNOPSIS
8 .LP
9 \fB#include <time.h>
10 .br
11 .sp
12 struct tm *localtime(const time_t *\fP\fItimer\fP\fB);
13 .br
14 \fP
15 .LP
16 \fBstruct tm *localtime_r(const time_t *restrict\fP \fItimer\fP\fB,
17 .br
18 \ \ \ \ \ \ struct tm *restrict\fP \fIresult\fP\fB); \fP
19 \fB
20 .br
21 \fP
22 .SH DESCRIPTION
23 .LP
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.
29 .LP
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().
35 .LP
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
39 as specified in the
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
43 any seasonal
44 time adjustments, where the names in the structure and in the expression
45 correspond.
46 .LP
47 The same relationship shall apply for \fIlocaltime_r\fP().
48 .LP
49 The
50 \fIlocaltime\fP() function need not be reentrant. A function that
51 is not required to be reentrant is not required to be
52 thread-safe.
53 .LP
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.
59 .LP
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
64 same structure.
65 .LP
66 Unlike \fIlocaltime\fP(), the reentrant version is not required to
67 set \fItzname\fP.
68 .SH RETURN VALUE
69 .LP
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.
74 .LP
75 Upon successful completion, \fIlocaltime_r\fP() shall return a pointer
76 to the structure pointed to by the argument \fIresult\fP.
77 .SH ERRORS
78 .LP
79 The \fIlocaltime\fP() function shall fail if:
80 .TP 7
81 .B EOVERFLOW
82 The result cannot be represented.
83 .sp
84 .LP
85 \fIThe following sections are informative.\fP
86 .SH EXAMPLES
87 .SS Getting the Local Date and Time
88 .LP
89 The following example uses the \fItime\fP() function to calculate
90 the time elapsed, in
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.
94 .sp
95 .RS
96 .nf
97
98 \fB#include <stdio.h>
99 #include <time.h>
100 .sp
101
102 int main(void)
103 {
104 time_t result;
105 .sp
106
107 result = time(NULL);
108 printf("%s%ju secs since the Epoch\\n",
109 asctime(localtime(&result)),
110 (uintmax_t)result);
111 return(0);
112 }
113 \fP
114 .fi
115 .RE
116 .LP
117 This example writes the current time to \fIstdout\fP in a form like
118 this:
119 .sp
120 .RS
121 .nf
122
123 \fBWed Jun 26 10:32:15 1996
124 835810335 secs since the Epoch
125 \fP
126 .fi
127 .RE
128 .SS Getting the Modification Time for a File
129 .LP
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(),
133 into a \fBtm\fP
134 structure that contains the year, month, day, and so on.
135 .sp
136 .RS
137 .nf
138
139 \fB#include <time.h>
140 \&...
141 struct stat statbuf;
142 \&...
143 tm = localtime(&statbuf.st_mtime);
144 \&...
145 \fP
146 .fi
147 .RE
148 .SS Timing an Event
149 .LP
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.
154 .sp
155 .RS
156 .nf
157
158 \fB#include <time.h>
159 #include <stdio.h>
160 \&...
161 time_t now;
162 int minutes_to_event;
163 \&...
164 time(&now);
165 printf("The time is ");
166 fputs(asctime(localtime(&now)), stdout);
167 printf("There are still %d minutes to the event.\\n",
168 minutes_to_event);
169 \&...
170 \fP
171 .fi
172 .RE
173 .SH APPLICATION USAGE
174 .LP
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.
178 .SH RATIONALE
179 .LP
180 None.
181 .SH FUTURE DIRECTIONS
182 .LP
183 None.
184 .SH SEE ALSO
185 .LP
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()
189 , the
190 Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI<time.h>\fP
191 .SH COPYRIGHT
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 .