1CTIME(3) Linux Programmer's Manual CTIME(3)
2
3
4
6 asctime, ctime, gmtime, localtime, mktime, asctime_r, ctime_r, gm‐
7 time_r, localtime_r - transform date and time to broken-down time or
8 ASCII
9
11 #include <time.h>
12
13 char *asctime(const struct tm *tm);
14 char *asctime_r(const struct tm *restrict tm, char *restrict buf);
15
16 char *ctime(const time_t *timep);
17 char *ctime_r(const time_t *restrict timep, char *restrict buf);
18
19 struct tm *gmtime(const time_t *timep);
20 struct tm *gmtime_r(const time_t *restrict timep,
21 struct tm *restrict result);
22
23 struct tm *localtime(const time_t *timep);
24 struct tm *localtime_r(const time_t *restrict timep,
25 struct tm *restrict result);
26
27 time_t mktime(struct tm *tm);
28
29 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
30
31 asctime_r(), ctime_r(), gmtime_r(), localtime_r():
32 _POSIX_C_SOURCE
33 || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
34
36 The ctime(), gmtime(), and localtime() functions all take an argument
37 of data type time_t, which represents calendar time. When interpreted
38 as an absolute time value, it represents the number of seconds elapsed
39 since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
40
41 The asctime() and mktime() functions both take an argument representing
42 broken-down time, which is a representation separated into year, month,
43 day, and so on.
44
45 Broken-down time is stored in the structure tm, which is defined in
46 <time.h> as follows:
47
48 struct tm {
49 int tm_sec; /* Seconds (0-60) */
50 int tm_min; /* Minutes (0-59) */
51 int tm_hour; /* Hours (0-23) */
52 int tm_mday; /* Day of the month (1-31) */
53 int tm_mon; /* Month (0-11) */
54 int tm_year; /* Year - 1900 */
55 int tm_wday; /* Day of the week (0-6, Sunday = 0) */
56 int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
57 int tm_isdst; /* Daylight saving time */
58 };
59
60 The members of the tm structure are:
61
62 tm_sec The number of seconds after the minute, normally in the range
63 0 to 59, but can be up to 60 to allow for leap seconds.
64
65 tm_min The number of minutes after the hour, in the range 0 to 59.
66
67 tm_hour The number of hours past midnight, in the range 0 to 23.
68
69 tm_mday The day of the month, in the range 1 to 31.
70
71 tm_mon The number of months since January, in the range 0 to 11.
72
73 tm_year The number of years since 1900.
74
75 tm_wday The number of days since Sunday, in the range 0 to 6.
76
77 tm_yday The number of days since January 1, in the range 0 to 365.
78
79 tm_isdst A flag that indicates whether daylight saving time is in ef‐
80 fect at the time described. The value is positive if day‐
81 light saving time is in effect, zero if it is not, and nega‐
82 tive if the information is not available.
83
84 The call ctime(t) is equivalent to asctime(localtime(t)). It converts