/* * time(&timer); returns the time since the Epoch (00:00:00 UTC, January 1, 1970), measured in seconds * 若是timer非空,也會把值放入timer */ time_t timer = time(NULL); //獲取具體的時間,以秒計 /** * clock()返回進程運行以來的clock tick數,linux下CLOCKS_PER_SEC=1,000,000 * 也就是說返回微妙數,不過從我觀察看,其最低三位通常是0,也就是說它能作到毫秒級別的精度 * 多用於計算時間差 */ clock_t t; int f; t = clock(); printf ("Calculating...\n"); f = frequency_of_primes (2500000); printf ("計算小於 2,500,000的素數的個數 is: %d\n",f); t = clock() - t; printf ("It took me %ld clicks (%f seconds) unit %ld.\n",t,((float)t)/CLOCKS_PER_SEC, CLOCKS_PER_SEC); /** * double difftime (time_t end, time_t beginning); * 返回end-beginning的秒數,保存爲浮點型數據 */ struct tm { int tm_sec; /* seconds 0-59*/ int tm_min; /* minutes 0-59*/ int tm_hour; /* hours 0-23*/ int tm_mday; /* day of the month 1-31*/ int tm_mon; /* month 0-11*/ int tm_year; /* year 真實年份-1900*/ int tm_wday; /* day of the week */ int tm_yday; /* day in the year */ int tm_isdst; /* daylight saving time */ }; /** * time_t mktime (struct tm * timeptr); * 把tm結構體轉換爲time_t格式的時間,tm_wday與tm_yday的值被忽略,其餘域值即便超出有效返回,也會被合理轉換,如tm_mday超過31時,也會被轉換爲以後月份的某一天 * timeptr指向的值有可能會被改變:若是tm_wday與tm_yday越過其有效範圍或者與其餘域的值不符,則會被調整爲正確的值 */ /** * struct tm * localtime (const time_t * timer); * 把time_t時間轉換爲tm時間,非線程安全 * 其線程安全版本爲:struct tm *localtime_r(const time_t *timep, struct tm *result); */ /** * size_t strftime (char* ptr, size_t maxsize, const char* format, const struct tm* timeptr ); * maxsize 包含結束符'\0'的長度 * format: %F表示YYYY-MM-DD,等效於%Y-%m-%d;%T表示HH:MM:SS,等效於%H:%M:%S */