Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | .\" Copyright (c) 1989, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" This code is derived from software contributed to Berkeley by | |
5 | .\" Arthur Olson. | |
6 | .\" Redistribution and use in source and binary forms, with or without | |
7 | .\" modification, are permitted provided that the following conditions | |
8 | .\" are met: | |
9 | .\" 1. Redistributions of source code must retain the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer. | |
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer in the | |
13 | .\" documentation and/or other materials provided with the distribution. | |
14 | .\" 3. All advertising materials mentioning features or use of this software | |
15 | .\" must display the following acknowledgement: | |
16 | .\" This product includes software developed by the University of | |
17 | .\" California, Berkeley and its contributors. | |
18 | .\" 4. Neither the name of the University nor the names of its contributors | |
19 | .\" may be used to endorse or promote products derived from this software | |
20 | .\" without specific prior written permission. | |
21 | .\" | |
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | .\" SUCH DAMAGE. | |
33 | .\" | |
34 | .\" @(#)ctime.3 6.15 (Berkeley) 4/19/91 | |
35 | .\" | |
36 | .Dd April 19, 1991 | |
37 | .Dt CTIME 3 | |
38 | .Os BSD 4.3 | |
39 | .Sh NAME | |
40 | .Nm asctime , | |
41 | .Nm ctime , | |
42 | .Nm difftime , | |
43 | .Nm gmtime , | |
44 | .Nm localtime , | |
45 | .Nm mktime | |
46 | .Nd transform binary date and time value to | |
47 | .Tn ASCII | |
48 | .Sh SYNOPSIS | |
49 | .Fd #include <sys/types.h> | |
50 | .Vt extern char *tzname[2]; | |
51 | .Ft char * | |
52 | .Fn ctime "const time_t *clock" | |
53 | .Ft double | |
54 | .Fn difftime "time_t time1" "time_t time0" | |
55 | .Fd #include <time.h> | |
56 | .Ft char * | |
57 | .Fn asctime "const struct tm *tm" | |
58 | .Ft struct tm * | |
59 | .Fn localtime "const time_t *clock" | |
60 | .Ft struct tm * | |
61 | .Fn gmtime "const time_t *clock" | |
62 | .Ft time_t | |
63 | .Fn mktime "struct tm *tm" | |
64 | .Sh DESCRIPTION | |
65 | The functions | |
66 | .Fn ctime , | |
67 | .Fn gmtime | |
68 | and | |
69 | .Fn localtime | |
70 | all take as an argument a time value representing the time in seconds since | |
71 | the Epoch (00:00:00 | |
72 | .Tn UTC , | |
73 | January 1, 1970; see | |
74 | .Xr time 3 ) . | |
75 | .Pp | |
76 | The function | |
77 | .Fn localtime | |
78 | converts the time value pointed at by | |
79 | .Fa clock , | |
80 | and returns a pointer to a | |
81 | .Dq Fa struct tm | |
82 | (described below) which contains | |
83 | the broken-out time information for the value after adjusting for the current | |
84 | time zone (and any other factors such as Daylight Saving Time). | |
85 | Time zone adjustments are performed as specified by the | |
86 | .Ev TZ | |
87 | environmental variable (see | |
88 | .Xr tzset 3 ) . | |
89 | The function | |
90 | .Fn localtime | |
91 | uses | |
92 | .Xr tzset | |
93 | to initialize time conversion information if | |
94 | .Xr tzset | |
95 | has not already been called by the process. | |
96 | .Pp | |
97 | After filling in the tm structure, | |
98 | .Fn localtime | |
99 | sets the | |
100 | .Fa tm_isdst Ns 'th | |
101 | element of | |
102 | .Fa tzname | |
103 | to a pointer to an | |
104 | .Tn ASCII | |
105 | string that's the time zone abbreviation to be | |
106 | used with | |
107 | .Fn localtime Ns 's | |
108 | return value. | |
109 | .Pp | |
110 | The function | |
111 | .Fn gmtime | |
112 | similarly converts the time value, but without any time zone adjustment, | |
113 | and returns a pointer to a tm structure (described below). | |
114 | .Pp | |
115 | The | |
116 | .Fn ctime | |
117 | function | |
118 | adjusts the time value for the current time zone in the same manner as | |
119 | .Fn localtime , | |
120 | and returns a pointer to a 26-character string of the form: | |
121 | .Bd -literal -offset indent | |
122 | Thu Nov 24 18:22:48 1986\en\e0 | |
123 | .Ed | |
124 | .Pp | |
125 | All the fields have constant width. | |
126 | .Pp | |
127 | The | |
128 | .Fn asctime | |
129 | function | |
130 | converts the broken down time in the structure | |
131 | .Fa tm | |
132 | pointed at by | |
133 | .Fa *tm | |
134 | to the form | |
135 | shown in the example above. | |
136 | .Pp | |
137 | The function | |
138 | .Fn mktime | |
139 | converts the broken-down time, expressed as local time, in the structure | |
140 | pointed to by tm into a time value with the same encoding as that of the | |
141 | values returned by the | |
142 | .Xr time 3 | |
143 | function, that is, seconds from the Epoch, | |
144 | .Tn UTC . | |
145 | .Pp | |
146 | The original values of the | |
147 | .Fa tm_wday | |
148 | and | |
149 | .Fa tm_yday | |
150 | components of the structure are ignored, and the original values of the | |
151 | other components are not restricted to their normal ranges. | |
152 | (A positive or zero value for | |
153 | .Fa tm_isdst | |
154 | causes | |
155 | .Fn mktime | |
156 | to presume initially that summer time (for example, Daylight Saving Time) | |
157 | is or is not in effect for the specified time, respectively. | |
158 | A negative value for | |
159 | .Fa tm_isdst | |
160 | causes the | |
161 | .Fn mktime | |
162 | function to attempt to divine whether summer time is in effect for the | |
163 | specified time.) | |
164 | .Pp | |
165 | On successful completion, the values of the | |
166 | .Fa tm_wday | |
167 | and | |
168 | .Fa tm_yday | |
169 | components of the structure are set appropriately, and the other components | |
170 | are set to represent the specified calendar time, but with their values | |
171 | forced to their normal ranges; the final value of | |
172 | .Fa tm_mday | |
173 | is not set until | |
174 | .Fa tm_mon | |
175 | and | |
176 | .Fa tm_year | |
177 | are determined. | |
178 | .Fn Mktime | |
179 | returns the specified calendar time; if the calendar time cannot be | |
180 | represented, it returns \-1; | |
181 | .Pp | |
182 | The | |
183 | .Fn difftime | |
184 | function | |
185 | returns the difference between two calendar times, | |
186 | .Pf ( Fa time1 | |
187 | - | |
188 | .Fa time0 ) , | |
189 | expressed in seconds. | |
190 | .Pp | |
191 | External declarations as well as the tm structure definition are in the | |
192 | .Aq Pa time.h | |
193 | include file. | |
194 | The tm structure includes at least the following fields: | |
195 | .Bd -literal -offset indent | |
196 | int tm_sec; /\(** seconds (0 - 60) \(**/ | |
197 | int tm_min; /\(** minutes (0 - 59) \(**/ | |
198 | int tm_hour; /\(** hours (0 - 23) \(**/ | |
199 | int tm_mday; /\(** day of month (1 - 31) \(**/ | |
200 | int tm_mon; /\(** month of year (0 - 11) \(**/ | |
201 | int tm_year; /\(** year \- 1900 \(**/ | |
202 | int tm_wday; /\(** day of week (Sunday = 0) \(**/ | |
203 | int tm_yday; /\(** day of year (0 - 365) \(**/ | |
204 | int tm_isdst; /\(** is summer time in effect? \(**/ | |
205 | char \(**tm_zone; /\(** abbreviation of timezone name \(**/ | |
206 | long tm_gmtoff; /\(** offset from UTC in seconds \(**/ | |
207 | .Ed | |
208 | .Pp | |
209 | The | |
210 | field | |
211 | .Fa tm_isdst | |
212 | is non-zero if summer time is in effect. | |
213 | .Pp | |
214 | The field | |
215 | .Fa tm_gmtoff | |
216 | is the offset (in seconds) of the time represented from | |
217 | .Tn UTC , | |
218 | with positive | |
219 | values indicating east of the Prime Meridian. | |
220 | .Sh SEE ALSO | |
221 | .Xr date 1 , | |
222 | .Xr gettimeofday 2 , | |
223 | .Xr getenv 3 , | |
224 | .Xr time 3 , | |
225 | .Xr tzset 3 , | |
226 | .Xr tzfile 5 | |
227 | .Sh HISTORY | |
228 | This manual page is derived from | |
229 | the time package contributed to Berkeley by | |
230 | Arthur Olsen and which appeared in | |
231 | .Bx 4.3 . | |
232 | .Sh BUGS | |
233 | Except for | |
234 | .Fn difftime | |
235 | and | |
236 | .Fn mktime , | |
237 | these functions leaves their result in an internal static object and return | |
238 | a pointer to that object. Subsequent calls to these | |
239 | function will modify the same object. | |
240 | .Pp | |
241 | The | |
242 | .Fa tm_zone | |
243 | field of a returned tm structure points to a static array of characters, | |
244 | which will also be overwritten by any subsequent calls (as well as by | |
245 | subsequent calls to | |
246 | .Xr tzset 3 | |
247 | and | |
248 | .Xr tzsetwall 3 ) . | |
249 | .Pp | |
250 | Use of the external variable | |
251 | .Fa tzname | |
252 | is discouraged; the | |
253 | .Fa tm_zone | |
254 | entry in the tm structure is preferred. | |
255 | .Pp | |
256 | Avoid using out-of-range values with | |
257 | .Fn mktime | |
258 | when setting up lunch with promptness sticklers in Riyadh. |