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