1ASCTIME(P) POSIX Programmer's Manual ASCTIME(P)
2
3
4
6 asctime, asctime_r - convert date and time to a string
7
9 #include <time.h>
10
11 char *asctime(const struct tm *timeptr);
12
13
14 char *asctime_r(const struct tm *restrict tm, char *restrict buf);
15
16
18 For asctime(): The functionality described on this reference page is
19 aligned with the ISO C standard. Any conflict between the requirements
20 described here and the ISO C standard is unintentional. This volume of
21 IEEE Std 1003.1-2001 defers to the ISO C standard.
22
23 The asctime() function shall convert the broken-down time in the struc‐
24 ture pointed to by timeptr into a string in the form:
25
26
27 Sun Sep 16 01:03:52 1973\n\0
28
29 using the equivalent of the following algorithm:
30
31
32 char *asctime(const struct tm *timeptr)
33 {
34 static char wday_name[7][3] = {
35 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
36 };
37 static char mon_name[12][3] = {
38 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
39 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
40 };
41 static char result[26];
42
43
44 sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
45 wday_name[timeptr->tm_wday],
46 mon_name[timeptr->tm_mon],
47 timeptr->tm_mday, timeptr->tm_hour,
48 timeptr->tm_min, timeptr->tm_sec,
49 1900 + timeptr->tm_year);
50 return result;
51 }
52
53 The tm structure is defined in the <time.h> header.
54
55 The asctime(), ctime(), gmtime(), and localtime() functions shall
56 return values in one of two static objects: a broken-down time struc‐
57 ture and an array of type char. Execution of any of the functions may
58 overwrite the information returned in either of these objects by any of
59 the other functions.
60
61 The asctime() function need not be reentrant. A function that is not
62 required to be reentrant is not required to be thread-safe.
63
64 The asctime_r() function shall convert the broken-down time in the
65 structure pointed to by tm into a string (of the same form as that
66 returned by asctime()) that is placed in the user-supplied buffer
67 pointed to by buf (which shall contain at least 26 bytes) and then
68 return buf.
69
71 Upon successful completion, asctime() shall return a pointer to the
72 string.
73
74 Upon successful completion, asctime_r() shall return a pointer to a
75 character string containing the date and time. This string is pointed
76 to by the argument buf. If the function is unsuccessful, it shall
77 return NULL.
78
80 No errors are defined.
81
82 The following sections are informative.
83
85 None.
86
88 Values for the broken-down time structure can be obtained by calling
89 gmtime() or localtime(). This function is included for compatibility
90 with older implementations, and does not support localized date and
91 time formats. Applications should use strftime() to achieve maximum
92 portability.
93
94 The asctime_r() function is thread-safe and shall return values in a
95 user-supplied buffer instead of possibly using a static data area that
96 may be overwritten by each call.
97
99 None.
100
102 None.
103
105 clock() , ctime() , difftime() , gmtime() , localtime() , mktime() ,
106 strftime() , strptime() , time() , utime() , the Base Definitions vol‐
107 ume of IEEE Std 1003.1-2001, <time.h>
108
110 Portions of this text are reprinted and reproduced in electronic form
111 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
112 -- Portable Operating System Interface (POSIX), The Open Group Base
113 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
114 Electrical and Electronics Engineers, Inc and The Open Group. In the
115 event of any discrepancy between this version and the original IEEE and
116 The Open Group Standard, the original IEEE and The Open Group Standard
117 is the referee document. The original Standard can be obtained online
118 at http://www.opengroup.org/unix/online.html .
119
120
121
122IEEE/The Open Group 2003 ASCTIME(P)