新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)C語言教程:C語言標(biāo)準(zhǔn)庫–
簡介
time.h 頭文件定義了四個(gè)變量類型、兩個(gè)宏和各種操作日期和時(shí)間的函數(shù)。

大連ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!
庫變量
下面是頭文件 time.h 中定義的變量類型:
| 序號(hào) | 變量 & 描述 |
|---|---|
| 1 | size_t 是無符號(hào)整數(shù)類型,它是 sizeof 關(guān)鍵字的結(jié)果。 |
| 2 | clock_t 這是一個(gè)適合存儲(chǔ)處理器時(shí)間的類型。 |
| 3 | time_t 這是一個(gè)適合存儲(chǔ)日歷時(shí)間類型。 |
| 4 | struct tm 這是一個(gè)用來保存時(shí)間和日期的結(jié)構(gòu)。 |
tm 結(jié)構(gòu)的定義如下:
struct tm {
int tm_sec; /* 秒,范圍從 0 到 59 */
int tm_min; /* 分,范圍從 0 到 59 */
int tm_hour; /* 小時(shí),范圍從 0 到 23 */
int tm_mday; /* 一月中的第幾天,范圍從 1 到 31 */
int tm_mon; /* 月,范圍從 0 到 11 */
int tm_year; /* 自 1900 年起的年數(shù) */
int tm_wday; /* 一周中的第幾天,范圍從 0 到 6 */
int tm_yday; /* 一年中的第幾天,范圍從 0 到 365 */
int tm_isdst; /* 夏令時(shí) */
};
庫宏
下面是頭文件 time.h 中定義的宏:
| 序號(hào) | 宏 & 描述 |
|---|---|
| 1 | NULL 這個(gè)宏是一個(gè)空指針常量的值。 |
| 2 | CLOCKS_PER_SEC 這個(gè)宏表示每秒的處理器時(shí)鐘個(gè)數(shù)。 |
庫函數(shù)
下面是頭文件 time.h 中定義的函數(shù):
| 序號(hào) | 函數(shù) & 描述 |
|---|---|
| 1 | char *asctime(const struct tm *timeptr) 返回一個(gè)指向字符串的指針,它代表了結(jié)構(gòu) timeptr 的日期和時(shí)間。 |
| 2 | clock_t clock(void) 返回程序執(zhí)行起(一般為程序的開頭),處理器時(shí)鐘所使用的時(shí)間。 |
| 3 | char *ctime(const time_t *timer) 返回一個(gè)表示當(dāng)?shù)貢r(shí)間的字符串,當(dāng)?shù)貢r(shí)間是基于參數(shù) timer。 |
| 4 | double difftime(time_t time1, time_t time2) 返回 time1 和 time2 之間相差的秒數(shù) (time1-time2)。 |
| 5 | struct tm *gmtime(const time_t *timer) timer 的值被分解為 tm 結(jié)構(gòu),并用協(xié)調(diào)世界時(shí)(UTC)也被稱為格林尼治標(biāo)準(zhǔn)時(shí)間(GMT)表示。 |
| 6 | struct tm *localtime(const time_t *timer) timer 的值被分解為 tm 結(jié)構(gòu),并用本地時(shí)區(qū)表示。 |
| 7 | time_t mktime(struct tm *timeptr) 把 timeptr 所指向的結(jié)構(gòu)轉(zhuǎn)換為一個(gè)依據(jù)本地時(shí)區(qū)的 time_t 值。 |
| 8 | size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr) 根據(jù) format 中定義的格式化規(guī)則,格式化結(jié)構(gòu) timeptr 表示的時(shí)間,并把它存儲(chǔ)在 str 中。 |
| 9 | time_t time(time_t *timer) 計(jì)算當(dāng)前日歷時(shí)間,并把它編碼成 time_t 格式。 |
當(dāng)前名稱:創(chuàng)新互聯(lián)C語言教程:C語言標(biāo)準(zhǔn)庫–
鏈接地址:http://www.5511xx.com/article/dhpdihc.html


咨詢
建站咨詢
