]> git.lizzy.rs Git - plan9front.git/blob - sys/man/2/ctime
9p(2): fix typo
[plan9front.git] / sys / man / 2 / ctime
1 .TH CTIME 2
2 .SH NAME
3 ctime, 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
11 char*   ctime(long clock)
12 .PP
13 .B
14 Tm*     localtime(long clock)
15 .PP
16 .B
17 Tm*     gmtime(long clock)
18 .PP
19 .B
20 char*   asctime(Tm *tm)
21 .PP
22 .B
23 long    tm2sec(Tm *tm)
24 .PP
25 .B
26 /env/timezone
27 .SH DESCRIPTION
28 .I Ctime
29 converts a time
30 .I clock
31 such as returned by
32 .IR time (2)
33 into
34 .SM ASCII
35 (sic)
36 and returns a pointer to a
37 30-byte string
38 in the following form.
39 All the fields have constant width.
40 .PP
41 .B
42         Wed Aug  5 01:07:47 EST 1973\en\e0
43 .PP
44 .I Localtime
45 and
46 .I gmtime
47 return pointers to structures containing
48 the broken-down time.
49 .I Localtime
50 corrects for the time zone and possible daylight savings time;
51 .I gmtime
52 converts directly to GMT.
53 .I Asctime
54 converts a broken-down time to
55 .SM ASCII
56 and returns a pointer
57 to a 30-byte string.
58 .IP
59 .EX
60 .ta 6n +\w'char 'u +\w'zone[4];    'u
61 typedef
62 struct {
63         int     sec;    /* seconds (range 0..59) */
64         int     min;    /* minutes (0..59) */
65         int     hour;   /* hours (0..23) */
66         int     mday;   /* day of the month (1..31) */
67         int     mon;    /* month of the year (0..11) */
68         int     year;   /* year A.D. \- 1900 */
69         int     wday;   /* day of week (0..6, Sunday = 0) */
70         int     yday;   /* day of year (0..365) */
71         char    zone[4];        /* time zone name */
72         int     tzoff;  /* time zone delta from GMT */
73 } Tm;
74 .EE
75 .PP
76 .I Tm2sec
77 converts a broken-down time to
78 seconds since the start of the epoch.
79 It ignores
80 .BR wday ,
81 and assumes the local time zone
82 if
83 .B zone
84 is not
85 .BR GMT .
86 .PP
87 When local time is first requested,
88 the program consults the
89 .B timezone
90 environment variable to determine the time zone and
91 converts accordingly.
92 (This variable is set at system boot time by
93 .IR init (8).)
94 The
95 .B timezone
96 variable contains
97 the normal time zone name and its difference from GMT
98 in seconds followed by an alternate (daylight) time zone name and
99 its difference followed by a newline.
100 The remainder is a list of pairs of times
101 (seconds past the start of 1970, in the first time zone)
102 when the alternate time zone applies.
103 For example:
104 .IP
105 .EX
106 EST -18000 EDT -14400
107  9943200 25664400 41392800 57718800 ...
108 .EE
109 .PP
110 Greenwich Mean Time is represented by
111 .IP
112 .EX
113 GMT 0 GMT 0
114 0
115 .EE
116 .SH SOURCE
117 .B /sys/src/libc/9sys
118 .SH "SEE ALSO"
119 .IR date (1),
120 .IR time (2),
121 .IR init (8)
122 .SH BUGS
123 The return values point to static data
124 whose content is overwritten by each call.
125 .br
126 Daylight Savings Time is ``normal'' in the Southern hemisphere.
127 .br
128 These routines are not equipped to handle non-\c
129 .SM ASCII
130 text, and are provincial anyway.