#include <SPAN style="FONT-FAMILY: Times New Roman"><stdio.h></SPAN> int main(void) { time_t t; t=time(NULL); printf("The number of seconds since January 1, 1970 is %d/n",t); return 0; }
運(yùn)行的結(jié)果與當(dāng)時(shí)的時(shí)間有關(guān),我當(dāng)時(shí)運(yùn)行的結(jié)果是: The Calendar Time now is 1266637045 其中1266637045就是我運(yùn)行程序時(shí)的日歷時(shí)間。即從1970年1月1日0時(shí)0分0秒到此時(shí)的秒數(shù)。 第6行中給time函數(shù)的參數(shù)設(shè)置為NULL,可得到具體的秒數(shù)。 可將第6行改寫為以下形式: time(&t); 變量t中存放當(dāng)前的日期和時(shí)間(相當(dāng)于函數(shù)返回值);