Unix紀元:1970年1月1日00:00:00
國際標準時間:本初子午線(地理經度起點)格林尼治天文臺原址時間,又稱格林尼治時間,UTC(Coordinated Universal Time,協調世界時)。
日曆時間:Unix紀元以來UTC所經過的秒數累計值。系統基本數據類型time_t
進程時間:即CPU時間,度量進程使用CPU資源,單位是時間滴答。系統基本數據類型clock_t
時鐘時間:牆上時間,進程運行時間總量。它與系統中同時運行的進程數有關。
用戶CPU時間:執行用戶指令所用的時間
系統CPU時間:執行內核程序所經歷的時間。
CPU時間:用戶CPU時間和系統CPU時間之和。time -p 程序
- #include <time.h>
- time_t time(time_t *calptr);//返回當前時間和日期
- struct timeval
- {
- time_t tv_sev;/* seconds */
- long tv_usec;/* microseconds */
- }
- #include <sys/time.h>
- int gettimeofday(struct timeval *restrict tp,void *restrict tzp);//tzp=NULL(必須)
- struct tm
- {
- int tm_sec;[0-60]
- int tm_min;[0-59]
- int tm_hour;[0-23]
- int tm_mday;[1-31]
- int tm_mon;[0-11]
- int tm_year;//從1900年經歷的年數
- int tm_wday;//從星期日經歷的天數
- int tm_yday;//從1月1日經歷的天數
- int tm_isdst;//夏時制標誌,夏時制生效正,非夏時制0,信息不可用負
- }
- #include<time.h>
- struct tm *gmtime(const time_t *calptr);//將日曆時間轉換成國際標準時間的年月日時分秒周
- struct tm *localtime(const time_t *calptr);//將日曆時間轉換成本地時間(考慮本地時區和夏時制)
- time_t mktime(struct tm *tmptr);//以本地時間的年月日等作爲參數,將其轉換成time_t
- char *asctime(const tm *tmptr);//返回26字節字符串
- char *ctime(const time_t *calptr);//返回26字節字符串
- /*複雜函數類似於printf,格式化時間結果放在長度爲maxsize個字符的buf數組中,返回值爲buf字符數,
- format參數控制時間值格式,轉換說明查表*/
- size_t strftime(char *restrict buf,size_t maxsize,
- const char *restrict format,
- const struct tm *restrict tmptr);
夏時令(summer time;daylight saving time-DST)
- 以下函數變成獲得進程的牆上時間和用戶CPU時間和系統CPU時間
- #include <sys/times.h>
- clock_t times(struct tms *buf);//返回牆上時間滴答數,前後做差值,函數填寫buf
- struct tms
- {
- clock_t tms_utime;//用戶CPU時間
- clock_t tms_stime;//系統CPU時間
- clock_t tms_cutime;//已終止的子進程用戶CPU時間
- clock_t tms_cstime;//已終止的子進程系統CPU時間
- }