C library function - asctime()
Description
C library function **char asctime(const struct tm timeptr) Returns a pointer to a string that represents the date and time of the struct timeptr structure.
Declaration
The following is the declaration of the asctime() function.
char *asctime(const struct tm *timeptr)
Parameters
timeptr is a pointer to a tm structure containing the calendar time broken down into the following parts:
struct tm {
int tm_sec; /* 秒,范围从 0 到 59 */
int tm_min; /* 分,范围从 0 到 59 */
int tm_hour; /* 小时,范围从 0 到 23 */
int tm_mday; /* 一月中的第几天,范围从 1 到 31 */
int tm_mon; /* 月份,范围从 0 到 11 */
int tm_year; /* 自 1900 起的年数 */
int tm_wday; /* 一周中的第几天,范围从 0 到 6 */
int tm_yday; /* 一年中的第几天,范围从 0 到 365 */
int tm_isdst; /* 夏令时 */
};
Return Value
This function returns a C string containing date and time information in a human-readable format Www Mmm dd hh:mm:ss yyyy, whereWww represents the day of the week,Mmm is the month in letters,dd represents the day of the month,hh:mm:ss represents the time,yyyy represents the year.
Example
The following example demonstrates the use of the asctime() function.
Example
#include
#include
#include
int
main
(
)
{
struct
tm
t
;
t.
tm_sec
=
10
;
t.
tm_min
=
10
;
t.
tm_hour
=
6
;
t.
tm_mday
=
25
;
t.
tm_mon
=
2
;
t.
tm_year
=
89
;
t.
tm_wday
=
6
;
puts
(
asctime
(
&
t
)
)
;
return
(
0
)
;
}
Let's compile and run the above program, which will produce the following result:
Sat Mar 25 06:10:10 1989
C Standard Library -