#include <stdio.h> #include <time.h> void main (void) { time_t secs; seconds = time(NULL); printf("secs ~ from January 1, 1970 to now = %ld", secs); return; }輸出: 1363069211
#include <stdio.h> #include <time.h> void main(void) { time_t t; struct tm *t_tm; t=1363069211 or time(&t) //system time; t_tm=gmtime(&t); char date[128]; strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", t_tm); printf("%d: %s\n", (int)t, date); return; }輸出: 1363069211: 2013-03-12 06:20:11 (差 +8 時區)
#include <stdio.h> #include <time.h> #include <unistd.h> void main(void) { time_t start, end; start = time(NULL); usleep(1200*1000); end = time(NULL); printf("end - start =%ld\n", end - start); return; }輸出: end - start = 1 (精準度只能到秒...)
一天的秒數: 86400
沒有留言:
張貼留言