add files fom from zcode2012e.tar.gz
[platform/upstream/tzdata.git] / newctime.3.txt
1 NEWCTIME(3)                                                        NEWCTIME(3)
2
3 NAME
4        asctime, ctime, difftime, gmtime, localtime, mktime - convert date and
5        time to ASCII
6
7 SYNOPSIS
8        extern char *tzname[2];
9
10        void tzset()
11
12        #include <sys/types.h>
13
14        char *ctime(clock)
15        const time_t *clock;
16
17        double difftime(time1, time0)
18        time_t time1;
19        time_t time0;
20
21        #include <time.h>
22
23        char *asctime(tm)
24        const struct tm *tm;
25
26        struct tm *localtime(clock)
27        const time_t *clock;
28
29        struct tm *gmtime(clock)
30        const time_t *clock;
31
32        time_t mktime(tm)
33        struct tm *tm;
34
35        cc ... -ltz
36
37 DESCRIPTION
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
44        form
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-
49        range years.
50
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.
57
58        Gmtime converts to Coordinated Universal Time.
59
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
62        string.
63
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.
83
84        Difftime returns the difference between two calendar times, (time1 -
85        time0), expressed in seconds.
86
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:
90
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 */
102
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.
107
108        Tm_isdst is non-zero if summer time is in effect.
109
110        Tm_gmtoff is the offset (in seconds) of the time represented from UTC,
111        with positive values indicating east of the Prime Meridian.
112
113 FILES
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
118
119        If /usr/local/etc/zoneinfo/GMT is absent, UTC leap seconds are loaded
120        from /usr/local/etc/zoneinfo/posixrules.
121
122 SEE ALSO
123        getenv(3), newstrftime(3), newtzset(3), time(2), tzfile(5)
124
125 NOTES
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).
130
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.
138
139        Avoid using out-of-range values with mktime when setting up lunch with
140        promptness sticklers in Riyadh.
141
142                                                                    NEWCTIME(3)