time.h 的函數 asctime() 將結構 tm 中所表示的時間格式轉換成字串,

因此以指向結構 tm 的指標當作參數,回傳表示此時間格式的字串。

#include <stdio.h>
#include <time.h>
 
int main(void)
{
    time_t t1 = time(NULL);
    struct tm *nPtr = localtime(&t1);
    char *now = asctime(nPtr);
     
    printf(now);
     
    return 0;
}

結果印出
星期  月  日   時:分:秒   年
文章標籤
全站熱搜
創作者介紹
創作者 pabeni 的頭像
pabeni

pabeni的部落格

pabeni 發表在 痞客邦 留言(0) 人氣(18)