blob: 65ab1d4122e20f518dbfcf2b40e58c0e6825d79c [file] [log] [blame]
rsc058b0112005-01-03 06:40:20 +00001.TH CTIME 3
2.SH NAME
3ctime, localtime, gmtime, asctime, tm2sec, timezone \- convert date and time
4.SH SYNOPSIS
5.B #include <u.h>
6.br
7.B #include <libc.h>
8.PP
9.ta \w'\fLchar* 'u
10.B
11char* ctime(long clock)
12.PP
13.B
14Tm* localtime(long clock)
15.PP
16.B
17Tm* gmtime(long clock)
18.PP
19.B
20char* asctime(Tm *tm)
21.PP
22.B
23long tm2sec(Tm *tm)
24.SH DESCRIPTION
25.I Ctime
26converts a time
27.I clock
28such as returned by
29.IR time (3)
30into
31.SM ASCII
32(sic)
33and returns a pointer to a
3430-byte string
35in the following form.
36All the fields have constant width.
37.PP
38.B
39 Wed Aug 5 01:07:47 EST 1973\en\e0
40.PP
41.I Localtime
42and
43.I gmtime
44return pointers to structures containing
45the broken-down time.
46.I Localtime
47corrects for the time zone and possible daylight savings time;
48.I gmtime
49converts directly to GMT.
50.I Asctime
51converts a broken-down time to
52.SM ASCII
53and returns a pointer
54to a 30-byte string.
55.IP
56.EX
57.ta 6n +\w'char 'u +\w'zone[4]; 'u
58typedef
59struct {
60 int sec; /* seconds (range 0..59) */
61 int min; /* minutes (0..59) */
62 int hour; /* hours (0..23) */
63 int mday; /* day of the month (1..31) */
64 int mon; /* month of the year (0..11) */
65 int year; /* year A.D. \- 1900 */
66 int wday; /* day of week (0..6, Sunday = 0) */
67 int yday; /* day of year (0..365) */
68 char zone[4]; /* time zone name */
69 int tzoff; /* time zone delta from GMT */
70} Tm;
71.EE
72.PP
73.I Tm2sec
74converts a broken-down time to
75seconds since the start of the epoch.
76It ignores
77.BR wday ,
78and assumes the local time zone
79if
80.B zone
81is not
82.BR GMT .
83.SH SOURCE
rscc3674de2005-01-11 17:37:33 +000084.B \*9/src/lib9/date.c
rsc058b0112005-01-03 06:40:20 +000085.br
rscc3674de2005-01-11 17:37:33 +000086.B \*9/src/lib9/ctime.c
rsc058b0112005-01-03 06:40:20 +000087.SH "SEE ALSO"
88.IR date (1),
89.IR time (3)
90.SH BUGS
91The return values point to static data
92whose content is overwritten by each call.
rscc8b63422005-01-13 04:49:19 +000093.PP
rsc058b0112005-01-03 06:40:20 +000094Daylight Savings Time is ``normal'' in the Southern hemisphere.
rscc8b63422005-01-13 04:49:19 +000095.PP
rsc058b0112005-01-03 06:40:20 +000096These routines are not equipped to handle non-\c
97.SM ASCII
98text, and are provincial anyway.
rscc8b63422005-01-13 04:49:19 +000099.PP
100To avoid name conflicts with the underlying system,
101.IR ctime ,
102.IR localtime ,
103.IR gmtime ,
104.IR asctime ,
105and
106.I tm2sec
107are preprocessor macros defined as
108.IR p9ctime ,
109.IR p9localtime ,
110.IR p9gmtime ,
111.IR p9asctime ,
112and
113.IR p9tm2sec ;
114see
115.IR intro (3).