3 asctime, ctime, difftime, gmtime, localtime, mktime -
4 convert date and time to ASCII
7 extern char *tzname[2];
11 #include <sys/types.h>
16 double difftime(time1, time0)
25 struct tm *localtime(clock)
28 struct tm *gmtime(clock)
37 Ctime converts a long integer, pointed to by clock,
38 representing the time in seconds since 00:00:00 UTC, 1970-
39 01-01, and returns a pointer to a string of the form
40 Thu Nov 24 18:22:48 1986\n\0
41 Years requiring fewer than four characters are padded with
42 leading zeroes. For years longer than four characters, the
44 Thu Nov 24 18:22:48 81986\n\0
45 with five spaces before the year. These unusual formats are
46 designed to make it less likely that older software that
47 expects exactly 26 bytes of output will mistakenly output
48 misleading values for out-of-range years.
50 Localtime and gmtime return pointers to ``tm'' structures,
51 described below. Localtime corrects for the time zone and
52 any time zone adjustments (such as Daylight Saving Time in
53 the United States). After filling in the ``tm'' structure,
54 localtime sets the tm_isdst'th element of tzname to a
55 pointer to an ASCII string that's the time zone abbreviation
56 to be used with localtime's return value.
58 Gmtime converts to Coordinated Universal Time.
60 Asctime converts a time value contained in a ``tm''
61 structure to a string, as shown in the above example, and
62 returns a pointer to the string.
64 Mktime converts the broken-down time, expressed as local
65 time, in the structure pointed to by tm into a calendar time
66 value with the same encoding as that of the values returned
67 by the time function. The original values of the tm_wday
68 and tm_yday components of the structure are ignored, and the
69 original values of the other components are not restricted
70 to their normal ranges. (A positive or zero value for
71 tm_isdst causes mktime to presume initially that summer time
72 (for example, Daylight Saving Time in the U.S.A.)
73 respectively, is or is not in effect for the specified time.
74 A negative value for tm_isdst causes the mktime function to
75 attempt to divine whether summer time is in effect for the
76 specified time.) On successful completion, the values of
77 the tm_wday and tm_yday components of the structure are set
78 appropriately, and the other components are set to represent
79 the specified calendar time, but with their values forced to
80 their normal ranges; the final value of tm_mday is not set
81 until tm_mon and tm_year are determined. Mktime returns the
82 specified calendar time; If the calendar time cannot be
83 represented, it returns -1.
85 Difftime returns the difference between two calendar times,
86 (time1 - time0), expressed in seconds.
88 Declarations of all the functions and externals, and the
89 ``tm'' structure, are in the <time.h> header file. The
90 structure (of type) struct tm includes the following fields:
92 int tm_sec; /* seconds (0 - 60) */
93 int tm_min; /* minutes (0 - 59) */
94 int tm_hour; /* hours (0 - 23) */
95 int tm_mday; /* day of month (1 - 31) */
96 int tm_mon; /* month of year (0 - 11) */
97 int tm_year; /* year - 1900 */
98 int tm_wday; /* day of week (Sunday = 0) */
99 int tm_yday; /* day of year (0 - 365) */
100 int tm_isdst; /* is summer time in effect? */
101 char *tm_zone; /* abbreviation of timezone name */
102 long tm_gmtoff; /* offset from UTC in seconds */
104 The tm_zone and tm_gmtoff fields exist, and are filled in,
105 only if arrangements to do so were made when the library
106 containing these functions was created. There is no
107 guarantee that these fields will continue to exist in this
108 form in future releases of this code.
110 Tm_isdst is non-zero if summer time is in effect.
112 Tm_gmtoff is the offset (in seconds) of the time represented
113 from UTC, with positive values indicating east of the Prime
117 /usr/local/etc/zoneinfo time zone information
119 /usr/local/etc/zoneinfo/localtime local time zone file
120 /usr/local/etc/zoneinfo/posixrules used with POSIX-style
122 /usr/local/etc/zoneinfo/GMT for UTC leap seconds
124 If /usr/local/etc/zoneinfo/GMT is absent, UTC leap seconds
125 are loaded from /usr/local/etc/zoneinfo/posixrules.
128 getenv(3), newstrftime(3), newtzset(3), time(2), tzfile(5)
131 The return values point to static data; the data is
132 overwritten by each call. The tm_zone field of a returned
133 struct tm points to a static array of characters, which will
134 also be overwritten at the next call (and by calls to
137 Asctime and ctime behave strangely for years before 1000 or
138 after 9999. The 1989 and 1999 editions of the C Standard
139 say that years from -99 through 999 are converted without
140 extra spaces, but this conflicts with longstanding tradition
141 and with this implementation. Traditional implementations
142 of these two functions are restricted to years in the range
143 1900 through 2099. To avoid this portability mess, new
144 programs should use strftime instead.
146 Avoid using out-of-range values with mktime when setting up
147 lunch with promptness sticklers in Riyadh.