
- C標準庫
- C庫 - 首頁
- C庫 - <assert.h>
- C庫 - <complex.h>
- C庫 - <ctype.h>
- C庫 - <errno.h>
- C庫 - <fenv.h>
- C庫 - <float.h>
- C庫 - <inttypes.h>
- C庫 - <iso646.h>
- C庫 - <limits.h>
- C庫 - <locale.h>
- C庫 - <math.h>
- C庫 - <setjmp.h>
- C庫 - <signal.h>
- C庫 - <stdalign.h>
- C庫 - <stdarg.h>
- C庫 - <stdbool.h>
- C庫 - <stddef.h>
- C庫 - <stdio.h>
- C庫 - <stdlib.h>
- C庫 - <string.h>
- C庫 - <tgmath.h>
- C庫 - <time.h>
- C庫 - <wctype.h>
- C程式設計資源
- C程式設計 - 教程
- C - 有用資源
C庫 - <time.h>
time.h 標頭檔案定義了四種變數型別、兩個宏和各種用於操作日期和時間的函式。
庫變數
以下是time.h標頭檔案中定義的變數型別:
序號 | 變數及描述 |
---|---|
1 |
size_t 這是一種無符號整型,是sizeof關鍵字的結果。 |
2 |
clock_t 這是一種適合儲存處理器時間的型別。 |
3 |
time_t 是 這是一種適合儲存日曆時間的型別。 |
4 |
struct tm 這是一個用於儲存時間和日期的結構體。 |
C庫宏
以下是time.h標頭檔案中定義的宏:
序號 | 宏及描述 |
---|---|
1 |
NULL 此宏是空指標常量的值。 |
2 |
CLOCKS_PER_SEC 此宏表示每秒的處理器時鐘數。 |
C庫 time.h 函式
以下是time.h標頭檔案中定義的函式:
序號 | 函式及描述 |
---|---|
1 |
char *asctime(const struct tm *timeptr)
返回一個指向字串的指標,該字串表示結構體timeptr的日期和時間。 |
2 |
clock_t clock(void)
返回自實現定義的紀元(通常是程式的開始)以來使用的處理器時鐘時間。 |
3 |
char *ctime(const time_t *timer)
返回基於引數timer的本地時間的字串表示。 |
4 |
double difftime(time_t time1, time_t time2)
返回time1和time2之間的秒差 (time1-time2)。 |
5 |
struct tm *gmtime(const time_t *timer)
timer的值被分解成結構體tm,並以協調世界時 (UTC) 表示,也稱為格林威治標準時間 (GMT)。 |
6 |
struct tm *localtime(const time_t *timer)
timer的值被分解成結構體tm,並以本地時區表示。 |
7 |
time_t mktime(struct tm *timeptr)
根據本地時區將timeptr指向的結構體轉換為time_t值。 |
8 |
size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr)
根據format中定義的格式規則格式化timeptr結構體中表示的時間,並將其儲存到str中。 |
9 |
time_t time(time_t *timer)
計算當前日曆時間並將其編碼為time_t格式。 |
10 |
size_t wcsftime( wchar_t* str, size_t count, const wchar_t* format, const struct tm* time )
將tm物件轉換為自定義寬字串文字表示。 |
廣告