time.h 頭定義了四個變量類型,兩個宏和用于操作的日期和時間的各種功能。
以下是在頭time.h中定義的變量類型:
| S.N. | 變量和說明 |
|---|---|
| 1 |
size_t 這是一個無符號整數(shù)類型的sizeof關(guān)鍵字的結(jié)果。 |
| 2 |
clock_t 這是一種適合用于存儲處理器的時間。 |
| 3 |
time_t is 這是一種適合用于存儲日歷時間。 |
| 4 |
struct tm 這是一個結(jié)構(gòu),用于保存的時間和日期。 |
tm結(jié)構(gòu)具有下列定義:
struct tm { int tm_sec; /* seconds, range 0 to 59 */ int tm_min; /* minutes, range 0 to 59 */ int tm_hour; /* hours, range 0 to 23 */ int tm_mday; /* day of the month, range 1 to 31 */ int tm_mon; /* month, range 0 to 11 */ int tm_year; /* The number of years since 1900 */ int tm_wday; /* day of the week, range 0 to 6 */ int tm_yday; /* day in the year, range 0 to 365 */ int tm_isdst; /* daylight saving time */ };
以下是在頭time.h中定義的宏:
| S.N. | 宏觀與說明 |
|---|---|
| 1 |
NULL 這個宏是一個空指針常量的值。 |
| 2 |
CLOCKS_PER_SEC 這個宏表示每秒的處理器時鐘周期的數(shù)目。 |
以下是在頭time.h中定義的函數(shù):
| S.N. | 函數(shù)及說明 |
|---|---|
| 1 |
char *asctime(const struct tm *timeptr) 將指針返回到一個字符串,它表示結(jié)構(gòu)timeptr 日期和時間。 |
| 2 |
clock_t clock(void) 返回處理器的時鐘使用,因為一個實(shí)現(xiàn)定義的時代的開始(通常是程序開頭)。 |
| 3 |
char *ctime(const time_t *timer) 返回一個字符串,代表localtime基于參數(shù)定時器。 |
| 4 |
double difftime(time_t time1, time_t time2) 返回秒時間1和時間2(時間1時間2)之間的差值。 |
| 5 |
struct tm *gmtime(const time_t *timer) 定時器的值被分解成結(jié)構(gòu)tm表示以協(xié)調(diào)通用時間(UTC),也被稱為格林威治標(biāo)準(zhǔn)時間(GMT)。 |
| 6 |
struct tm *localtime(const time_t *timer) 定時器的值被分解成結(jié)構(gòu)tm表示本地時區(qū)。 |
| 7 |
time_t mktime(struct tm *timeptr) 結(jié)構(gòu)轉(zhuǎn)換所指出timeptr成一個time_t值,根據(jù)本地時區(qū)。 |
| 8 |
size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr) 格式結(jié)構(gòu)timeptr根據(jù)定義格式并存儲到str格式規(guī)則表示的時間。 |
| 9 |
time_t time(time_t *timer) 計算當(dāng)前壓延時間,并將其編碼成time_t的格式。 |