Linux C function() 參考手冊:localtime(取得當地目前時間和日期)
Linux C function() 參考手冊:localtime(取得當地目前時間和日期)
資料來源:http://people.cs.nctu.edu.tw/~yslin/library/linuxc/main.htm
線上執行:http://www.tutorialspoint.com/compile_c_online.php
code2html:http://tohtml.com/
#include <time.h> #include <stdio.h> int main() { char *wday[]={"Sun(日)","Mon(一)","Tue(二)","Wed(三)","Thu(四)","Fri(五)","Sat(六)"}; time_t timep; struct tm *p; time(&timep); p=localtime(&timep); /*取得當地時間*/ printf ("%d/%d/%d", (1900+p->tm_year),p->tm_mon+1, p->tm_mday); printf("%s% d:%d:%d\n", wday[p->tm_wday],p->tm_hour, p->tm_min, p->tm_sec); return 0; }