"Fossies" - the Fresh Open Source Software Archive
Member "newctime.3.txt" (25 Nov 2022, 8419 Bytes) of package /linux/misc/tzcode2022g.tar.gz:
As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard
) with prefixed line numbers.
Alternatively you can here view
the uninterpreted source code file.
See also the last Fossies "Diffs"
side-by-side code changes report for "newctime.3.txt": 2021e_vs_2022e
1 NEWCTIME(3) Library Functions Manual NEWCTIME(3)
4 asctime, ctime, difftime, gmtime, localtime, mktime - convert date and
8 #include <time.h>
10 extern char *tzname; /* (optional) */
12 char *ctime(time_t const *clock);
14 char *ctime_r(time_t const *clock, char *buf);
16 double difftime(time_t time1, time_t time0);
18 char *asctime(struct tm const *tm);
20 char *asctime_r(struct tm const *restrict tm,
21 char *restrict result);
23 struct tm *localtime(time_t const *clock);
25 struct tm *localtime_r(time_t const *restrict clock,
26 struct tm *restrict result);
28 struct tm *localtime_rz(timezone_t restrict zone,
29 time_t const *restrict clock,
30 struct tm *restrict result);
32 struct tm *gmtime(time_t const *clock);
34 struct tm *gmtime_r(time_t const *restrict clock,
35 struct tm *restrict result);
37 time_t mktime(struct tm *tm);
39 time_t mktime_z(timezone_t restrict zone,
40 struct tm *restrict tm);
42 cc ... -ltz
45 The ctime function converts a long integer, pointed to by clock, and
46 returns a pointer to a string of the form
47 Thu Nov 24 18:22:48 1986\n\0
48 Years requiring fewer than four characters are padded with leading
49 zeroes. For years longer than four characters, the string is of the
51 Thu Nov 24 18:22:48 81986\n\0
52 with five spaces before the year. These unusual formats are designed
53 to make it less likely that older software that expects exactly 26
54 bytes of output will mistakenly output misleading values for out-of-
55 range years.
57 The *clock timestamp represents the time in seconds since 1970-01-01
58 00:00:00 Coordinated Universal Time (UTC). The POSIX standard says
59 that timestamps must be nonnegative and must ignore leap seconds. Many
60 implementations extend POSIX by allowing negative timestamps, and can
61 therefore represent timestamps that predate the introduction of UTC and
62 are some other flavor of Universal Time (UT). Some implementations
63 support leap seconds, in contradiction to POSIX.
65 The localtime and gmtime functions return pointers to "tm" structures,
66 described below. The localtime function corrects for the time zone and
67 any time zone adjustments (such as Daylight Saving Time in the United
68 States). After filling in the "tm" structure, localtime sets the
69 tm_isdst'th element of tzname to a pointer to a string that's the time
70 zone abbreviation to be used with localtime's return value.
72 The gmtime function converts to Coordinated Universal Time.
74 The asctime function converts a time value contained in a "tm"
75 structure to a string, as shown in the above example, and returns a
76 pointer to the string.
78 The mktime function converts the broken-down time, expressed as local
79 time, in the structure pointed to by tm into a calendar time value with
80 the same encoding as that of the values returned by the time function.
81 The original values of the tm_wday and tm_yday components of the
82 structure are ignored, and the original values of the other components
83 are not restricted to their normal ranges. (A positive or zero value
84 for tm_isdst causes mktime to presume initially that daylight saving
85 time respectively, is or is not in effect for the specified time. A
86 negative value for tm_isdst causes the mktime function to attempt to
87 divine whether daylight saving time is in effect for the specified
88 time; in this case it does not use a consistent rule and may give a
89 different answer when later presented with the same argument.) On
90 successful completion, the values of the tm_wday and tm_yday components
91 of the structure are set appropriately, and the other components are
92 set to represent the specified calendar time, but with their values
93 forced to their normal ranges; the final value of tm_mday is not set
94 until tm_mon and tm_year are determined. The mktime function returns
95 the specified calendar time; If the calendar time cannot be
96 represented, it returns -1.
98 The difftime function returns the difference between two calendar
99 times, (time1 - time0), expressed in seconds.
101 The ctime_r, localtime_r, gmtime_r, and asctime_r functions are like
102 their unsuffixed counterparts, except that they accept an additional
103 argument specifying where to store the result if successful.
105 The localtime_rz and mktime_z functions are like their unsuffixed
106 counterparts, except that they accept an extra initial zone argument
107 specifying the timezone to be used for conversion. If zone is null, UT
108 is used; otherwise, zone should be have been allocated by tzalloc and
109 should not be freed until after all uses (e.g., by calls to strftime)
110 of the filled-in tm_zone fields.
112 Declarations of all the functions and externals, and the "tm"
113 structure, are in the <time.h> header file. The structure (of type)
114 struct tm includes the following fields:
116 int tm_sec; /* seconds (0-60) */
117 int tm_min; /* minutes (0-59) */
118 int tm_hour; /* hours (0-23) */
119 int tm_mday; /* day of month (1-31) */
120 int tm_mon; /* month of year (0-11) */
121 int tm_year; /* year - 1900 */
122 int tm_wday; /* day of week (Sunday = 0) */
123 int tm_yday; /* day of year (0-365) */
124 int tm_isdst; /* is daylight saving time in effect? */
125 char *tm_zone; /* time zone abbreviation (optional) */
126 long tm_gmtoff; /* offset from UT in seconds (optional) */
128 The tm_isdst field is non-zero if daylight saving time is in effect.
130 The tm_gmtoff field is the offset (in seconds) of the time represented
131 from UT, with positive values indicating east of the Prime Meridian.
132 The field's name is derived from Greenwich Mean Time, a precursor of
135 In struct tm the tm_zone and tm_gmtoff fields exist, and are filled in,
136 only if arrangements to do so were made when the library containing
137 these functions was created. Similarly, the tzname variable is
138 optional; also, there is no guarantee that tzname will continue to
139 exist in this form in future releases of this code.
142 /usr/share/zoneinfo timezone information directory
143 /usr/share/zoneinfo/localtime local timezone file
144 /usr/share/zoneinfo/posixrules used with POSIX-style TZ's
145 /usr/share/zoneinfo/GMT for UTC leap seconds
147 If /usr/share/zoneinfo/GMT is absent, UTC leap seconds are loaded from
150 SEE ALSO
151 getenv(3), newstrftime(3), newtzset(3), time(2), tzfile(5)
154 The return values of asctime, ctime, gmtime, and localtime point to
155 static data overwritten by each call. The tzname variable (once set)
156 and the tm_zone field of a returned struct tm both point to an array of
157 characters that can be freed or overwritten by later calls to the
158 functions localtime, tzfree, and tzset, if these functions affect the
159 timezone information that specifies the abbreviation in question. The
160 remaining functions and data are thread-safe.
162 The asctime, asctime_r, ctime, and ctime_r functions behave strangely
163 for years before 1000 or after 9999. The 1989 and 1999 editions of the
164 C Standard say that years from -99 through 999 are converted without
165 extra spaces, but this conflicts with longstanding tradition and with
166 this implementation. The 2011 edition says that the behavior is
167 undefined if the year is before 1000 or after 9999. Traditional
168 implementations of these two functions are restricted to years in the
169 range 1900 through 2099. To avoid this portability mess, new programs
170 should use strftime instead.