C 庫函數(shù) - asctime()
描述
C 庫函數(shù) char *asctime(const struct tm *timeptr) 返回一個(gè)指向字符串的指針,它代表了結(jié)構(gòu) struct timeptr 的日期和時(shí)間。
聲明
下面是 asctime() 函數(shù)的聲明。
char *asctime(const struct tm *timeptr)
參數(shù)
timeptr 是指向 tm 結(jié)構(gòu)的指針,包含了分解為如下各部分的日歷時(shí)間:
struct tm { int tm_sec; /* 秒,范圍從 0 到 59 */ int tm_min; /* 分,范圍從 0 到 59 */ int tm_hour; /* 小時(shí),范圍從 0 到 23 */ int tm_mday; /* 一月中的第幾天,范圍從 1 到 31 */ int tm_mon; /* 月份,范圍從 0 到 11 */ int tm_year; /* 自 1900 起的年數(shù) */ int tm_wday; /* 一周中的第幾天,范圍從 0 到 6 */ int tm_yday; /* 一年中的第幾天,范圍從 0 到 365 */ int tm_isdst; /* 夏令時(shí) */ };
返回值
該函數(shù)返回一個(gè) C 字符串,包含了可讀格式的日期和時(shí)間信息 Www Mmm dd hh:mm:ss yyyy,其中,Www 表示星期幾,Mmm 是以字母表示的月份,dd 表示一月中的第幾天,hh:mm:ss 表示時(shí)間,yyyy 表示年份。
實(shí)例
下面的實(shí)例演示了 asctime() 函數(shù)的用法。
#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); }
讓我們編譯并運(yùn)行上面的程序,這將產(chǎn)生以下結(jié)果:
Sat Mar 25 06:10:10 1989
更多建議: