reduce size of devname entry
[unix-history] / usr / src / lib / libc / gen / ctime.3
CommitLineData
637a994b
KB
1.\" Copyright (c) 1989 The Regents of the University of California.
2.\" All rights reserved.
463d6749 3.\"
637a994b
KB
4.\" This code is derived from software contributed to Berkeley by
5.\" Arthur Olson.
463d6749 6.\"
91cff1e1 7.\" %sccs.include.redist.man%
637a994b 8.\"
91cff1e1 9.\" @(#)ctime.3 6.13 (Berkeley) %G%
637a994b
KB
10.\"
11.TH CTIME 3 ""
463d6749 12.SH NAME
637a994b 13asctime, ctime, difftime, gmtime, localtime, mktime, tzset, tzsetwall \- convert date and time to ASCII
463d6749
KM
14.SH SYNOPSIS
15.nf
637a994b
KB
16.B extern char *tzname[2];
17.PP
94c2eda1
KB
18.B void tzset()
19.PP
637a994b
KB
20.B void tzsetwall()
21.PP
22.B #include <sys/types.h>
23.PP
463d6749 24.B char *ctime(clock)
94c2eda1 25.B time_t *clock;
463d6749 26.PP
637a994b
KB
27.B double difftime(time1, time0)
28.B time_t time1;
29.B time_t time0;
30.PP
2ad48aae 31.B #include <time.h>
463d6749 32.PP
94c2eda1
KB
33.B char *asctime(tm)
34.B struct tm *tm;
35.PP
463d6749 36.B struct tm *localtime(clock)
637a994b 37.B long *clock;
463d6749
KM
38.PP
39.B struct tm *gmtime(clock)
637a994b 40.B long *clock;
463d6749 41.PP
637a994b
KB
42.B time_t mktime(tm)
43.B struct tm *tm;
94c2eda1 44.fi
463d6749 45.SH DESCRIPTION
637a994b
KB
46.I Tzset
47uses the value of the environment variable
48.B TZ
49to set time conversion information used by
50.IR localtime .
51If
52.B TZ
53does not appear in the environment,
54the best available approximation to local wall clock time, as specified
55by the
56.IR tzfile (5)-format
57file
58.B localtime
59in the system time conversion information directory, is used by
60.IR localtime .
61If
62.B TZ
63appears in the environment but its value is a null string,
64Coordinated Universal Time (UTC) is used (without leap second
65correction). If
66.B TZ
67appears in the environment and its value is not a null string:
68.IP
69if the value begins with a colon, it is used as a pathname of a file
70from which to read the time conversion information;
71.IP
72if the value does not begin with a colon, it is first used as the
73pathname of a file from which to read the time conversion information,
74and, if that file cannot be read, is used directly as a specification of
75the time conversion information.
76.PP
77When
78.B TZ
79is used as a pathname, if it begins with a slash,
80it is used as an absolute pathname; otherwise,
81it is used as a pathname relative to a system time conversion information
82directory.
83The file must be in the format specified in
84.IR tzfile (5).
85.PP
86When
87.B TZ
88is used directly as a specification of the time conversion information,
89it must have the following syntax (spaces inserted for clarity):
90.IP
91\fIstd\|offset\fR[\fIdst\fR[\fIoffset\fR][\fB,\fIrule\fR]]
92.PP
93Where:
94.RS
95.TP 15
96.IR std " and " dst
97Three or more bytes that are the designation for the standard
98.RI ( std )
99or summer
100.RI ( dst )
101time zone. Only
102.I std
103is required; if
104.I dst
105is missing, then summer time does not apply in this locale.
106Upper- and lowercase letters are explicitly allowed. Any characters
107except a leading colon
108.RB ( : ),
109digits, comma
110.RB ( , ),
111minus
112.RB ( \(mi ),
113plus
114.RB ( \(pl ),
115and ASCII NUL are allowed.
116.TP
117.I offset
118Indicates the value one must add to the local time to arrive at
119Coordinated Universal Time. The
120.I offset
121has the form:
122.RS
123.IP
124\fIhh\fR[\fB:\fImm\fR[\fB:\fIss\fR]]
125.RE
126.IP
127The minutes
128.RI ( mm )
129and seconds
130.RI ( ss )
131are optional. The hour
132.RI ( hh )
133is required and may be a single digit. The
134.I offset
135following
136.I std
137is required. If no
138.I offset
139follows
140.IR dst ,
141summer time is assumed to be one hour ahead of standard time. One or
142more digits may be used; the value is always interpreted as a decimal
143number. The hour must be between zero and 24, and the minutes (and
144seconds) \(em if present \(em between zero and 59. If preceded by a
145.RB `` \(mi '',
146the time zone shall be east of the Prime Meridian; otherwise it shall be
147west (which may be indicated by an optional preceding
148.RB `` \(pl '').
149.TP
150.I rule
151Indicates when to change to and back from summer time. The
152.I rule
153has the form:
154.RS
155.IP
156\fIdate\fB/\fItime\fB,\fIdate\fB/\fItime\fR
157.RE
158.IP
159where the first
160.I date
161describes when the change from standard to summer time occurs and the
162second
163.I date
164describes when the change back happens. Each
165.I time
166field describes when, in current local time, the change to the other
167time is made.
168.IP
169The format of
170.I date
171is one of the following:
172.RS
173.TP 10
174.BI J n
175The Julian day
176.I n
177.RI "(1\ \(<=" "\ n\ " "\(<=\ 365).
178Leap days are not counted; that is, in all years \(em including leap
179years \(em February 28 is day 59 and March 1 is day 60. It is
180impossible to explicitly refer to the occasional February 29.
181.TP
182.I n
183The zero-based Julian day
184.RI "(0\ \(<=" "\ n\ " "\(<=\ 365).
185Leap days are counted, and it is possible to refer to February 29.
186.TP
187.BI M m . n . d
188The
189.IR d' th
190day
191.RI "(0\ \(<=" "\ d\ " "\(<=\ 6)
192of week
193.I n
194of month
195.I m
196of the year
197.RI "(1\ \(<=" "\ n\ " "\(<=\ 5,
198.RI "1\ \(<=" "\ m\ " "\(<=\ 12,
199where week 5 means ``the last
200.I d
201day in month
202.IR m ''
203which may occur in either the fourth or the fifth week). Week 1 is the
204first week in which the
205.IR d' th
206day occurs. Day zero is Sunday.
207.RE
208.IP "" 15
209The
210.I time
211has the same format as
212.I offset
213except that no leading sign
214.RB (`` \(mi ''
215or
216.RB `` \(pl '')
217is allowed. The default, if
218.I time
219is not given, is
220.BR 02:00:00 .
221.RE
222.LP
223If no
224.I rule
225is present in
226.BR TZ ,
227the rules specified
228by the
229.IR tzfile (5)-format
230file
231.B posixrules
232in the system time conversion information directory are used, with the
233standard and summer time offsets from UTC replaced by those specified by
234the
235.I offset
236values in
237.BR TZ .
238.PP
239For compatibility with System V Release 3.1, a semicolon
240.RB ( ; )
241may be used to separate the
242.I rule
243from the rest of the specification.
244.PP
245If the
246.B TZ
247environment variable does not specify a
248.IR tzfile (5)-format
249and cannot be interpreted as a direct specification,
de716a99 250UTC is used.
637a994b
KB
251.PP
252.I Tzsetwall
253sets things up so that
254.I localtime
255returns the best available approximation of local wall clock time.
256.PP
257.I Ctime\^
258converts a long integer, pointed to by
259.IR clock ,
260representing the time in seconds since
26100:00:00 UTC, January 1, 1970,
262and returns a pointer to a
26326-character string
264of the form
265.br
266.ce
267.eo
268Thu Nov 24 18:22:48 1986\n\0
269.ec
270.br
271All the fields have constant width.
272.PP
273.IR Localtime\^
463d6749 274and
637a994b
KB
275.I gmtime\^
276return pointers to ``tm'' structures, described below.
277.I Localtime\^
278corrects for the time zone and any time zone adjustments
279(such as Daylight Saving Time in the U.S.A.).
280Before doing so,
281.I localtime\^
282calls
283.I tzset\^
284(if
285.I tzset\^
286has not been called in the current process).
287After filling in the ``tm'' structure,
288.I localtime
289sets the
290.BR tm_isdst 'th
291element of
292.B tzname
293to a pointer to an
294ASCII string that's the time zone abbreviation to be used with
295.IR localtime 's
296return value.
297.PP
298.I Gmtime\^
299converts to Coordinated Universal Time.
300.PP
301.I Asctime\^
302converts a time value contained in a
303``tm'' structure to a 26-character string,
304as shown in the above example,
305and returns a pointer
306to the string.
463d6749 307.PP
637a994b
KB
308.I Mktime\^
309converts the broken-down time,
310expressed as local time,
311in the structure pointed to by
312.I tm
313into a calendar time value with the same encoding as that of the values
314returned by the
315.I time
316function.
317The original values of the
318.B tm_wday
319and
320.B tm_yday
321components of the structure are ignored,
322and the original values of the other components are not restricted
323to their normal ranges.
324(A positive or zero value for
325.B tm_isdst
326causes
327.I mktime
328to presume initially that summer time (for example, Daylight Saving Time
329in the U.S.A.)
330respectively,
331is or is not in effect for the specified time.
332A negative value for
333.B tm_isdst
334causes the
335.I mktime
336function to attempt to divine whether summer time is in effect
337for the specified time.)
338On successful completion, the values of the
339.B tm_wday
340and
341.B tm_yday
342components of the structure are set appropriately,
343and the other components are set to represent the specified calendar time,
344but with their values forced to their normal ranges; the final value of
345.B tm_mday
346is not set until
347.B tm_mon
348and
349.B tm_year
350are determined.
351.I Mktime\^
352returns the specified calendar time;
353If the calendar time cannot be represented,
354it returns
355.BR -1 .
356.PP
357.I Difftime\^
358returns the difference between two calendar times,
359.I time1
360-
361.IR time0,
362expressed in seconds.
363.PP
364Declarations of all the functions and externals, and the ``tm'' structure,
365are in the
366.B <time.h>\^
367header file.
368The structure (of type)
369.B struct tm
370includes the following fields:
8eafd288 371.RS
637a994b 372.PP
463d6749 373.nf
637a994b
KB
374.ta .5i +\w'long tm_gmtoff;\0\0'u
375 int tm_sec; /\(** seconds (0 - 60) \(**/
376 int tm_min; /\(** minutes (0 - 59) \(**/
377 int tm_hour; /\(** hours (0 - 23) \(**/
378 int tm_mday; /\(** day of month (1 - 31) \(**/
379 int tm_mon; /\(** month of year (0 - 11) \(**/
380 int tm_year; /\(** year \- 1900 \(**/
381 int tm_wday; /\(** day of week (Sunday = 0) \(**/
382 int tm_yday; /\(** day of year (0 - 365) \(**/
383 int tm_isdst; /\(** is summer time in effect? \(**/
384 char \(**tm_zone; /\(** abbreviation of timezone name \(**/
385 long tm_gmtoff; /\(** offset from UTC in seconds \(**/
463d6749
KM
386.fi
387.RE
388.PP
637a994b
KB
389The
390.I tm_zone
391and
392.I tm_gmtoff
393fields exist, and are filled in, only if arrangements to do
394so were made when the library containing these functions was
395created.
396There is no guarantee that these fields will continue to exist
397in this form in future releases of this code.
398.PP
399.I Tm_isdst\^
400is non-zero if summer time is in effect.
401.PP
402.I Tm_gmtoff
403is the offset (in seconds) of the time represented
404from UTC, with positive values indicating east
405of the Prime Meridian.
94c2eda1 406.SH FILES
b13dc0cc
TH
407.ta \w'/usr/share/zoneinfo/posixrules\0\0'u
408/usr/share/zoneinfo time zone information directory
94c2eda1 409.br
b13dc0cc 410/usr/share/zoneinfo/localtime local time zone file
637a994b 411.br
b13dc0cc 412/usr/share/zoneinfo/posixrules used in converting POSIX-style TZ's
637a994b 413.br
b13dc0cc 414/usr/share/zoneinfo/GMT for UTC leap seconds
637a994b
KB
415.sp
416If
b13dc0cc 417.I /usr/share/zoneinfo/GMT
637a994b
KB
418is absent,
419UTC leap seconds are loaded from
b13dc0cc 420.IR /usr/share/zoneinfo/posixrules .
94c2eda1 421.SH SEE ALSO
637a994b
KB
422time(2), getenv(3), tzfile(5)
423.SH NOTES
424The return values point to static data
425whose content is overwritten by each call.
426The
427.B tm_zone
428field of a returned
429.B "struct tm"
430points to a static array of characters, which
431will also be overwritten at the next call
432(and by calls to
433.I tzset
434or
435.IR tzsetwall ).
436.PP
437Avoid using out-of-range values with
438.I mktime
439when setting up lunch with promptness sticklers in Riyadh.