C library functions - asctime ()
description
C library functionschar * asctime (const struct tm * timeptr) returns a pointer to a string that represents the date and time of the structure struct timeptr.
statement
The following is a statement asctime () function.
char *asctime(const struct tm *timeptr)
parameter
timeptr tm structure is a pointer to a pointer, broken down into the following calendar contains the time of each section:
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 that contains the date and time information in a readable formatWww Mmm dd hh: mm: ss yyyy , where,Wwwday of theweek,Mmm is amonth-letter,dd represents the first of the month A fewdays,hh: mm: ss representstime,yyyy represents the year.
Examples
The following example demonstrates asctime () function is used.
#include <stdio.h> #include <string.h> #include <time.h> 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 result in the following:
Sat Mar 25 06:10:10 1989