命名空间
变体
操作

标准库头文件 <time.h>

来自 cppreference.cn
< c‎ | 头文件

此头文件是日期和时间工具库的一部分。

目录

[编辑] 函数

时间操作
计算时间差
(函数) [编辑]
返回系统当前日历时间,自纪元起的时间
(函数) [编辑]
返回程序启动以来原始处理器时钟时间
(函数) [编辑]
根据给定时间基准返回以秒和纳秒表示的日历时间
(函数) [编辑]
根据给定时间基准返回日历时间的分辨率
(函数) [编辑]
格式转换
(C23 中已废弃)(C11)
tm 对象转换为文本表示
(函数) [编辑]
(C23 中已废弃)(C11)
time_t 对象转换为文本表示形式
(函数) [编辑]
tm 对象转换为自定义文本表示形式
(函数) [编辑]
将自纪元以来的时间转换为协调世界时 (UTC) 表示的日历时间
(函数) [编辑]
将自纪元以来的时间转换为以本地时间表示的日历时间
(函数) [编辑]
将日历时间转换为自纪元以来的时间
(函数) [编辑]

[编辑] 常量

每秒的处理器时钟节拍数
(宏常量) [编辑]

[编辑] 类型

日历时间类型
(结构体)[编辑]
自纪元以来的日历时间类型
(类型定义) [编辑]
自纪元以来的处理器时间类型
(类型定义) [编辑]
秒和纳秒时间
(结构体)[编辑]

[编辑] 概要

#define __STDC_VERSION_TIME_H__ 202311L
 
#define NULL           /* see description */
#define CLOCKS_PER_SEC /* see description */
#define TIME_UTC       /* see description */
 
typedef /* see description */ clock_t;
typedef /* see description */ size_t;
typedef /* see description */ time_t;
 
struct timespec { /* see description */ };
struct tm { /* see description */ };
 
clock_t clock(void);
double difftime(time_t time1, time_t time0);
time_t mktime(struct tm* timeptr);
time_t timegm(struct tm* timeptr);
time_t time(time_t* timer);
int timespec_get(struct timespec* ts, int base);
int timespec_getres(struct timespec* ts, int base);
[[deprecated]] char* asctime(const struct tm* timeptr);
[[deprecated]] char* ctime(const time_t* timer);
struct tm* gmtime(const time_t* timer);
struct tm* gmtime_r(const time_t* timer, struct tm* buf);
struct tm* localtime(const time_t* timer);
struct tm* localtime_r(const time_t* timer, struct tm* buf);
size_t strftime(char* restrict s, size_t maxsize, const char* restrict format,
const struct tm* restrict timeptr);

仅当实现支持时

#define TIME_MONOTONIC /* see description */
#define TIME_ACTIVE    /* see description */

仅当支持线程且实现支持时

#define TIME_THREAD_ACTIVE /* see description */

仅当实现定义了 __STDC_LIB_EXT1__ 且用户代码在包含 <time.h> 之前定义了 __STDC_WANT_LIB_EXT1__

#ifdef __STDC_WANT_LIB_EXT1__
typedef /* see description */ errno_t;
typedef /* see description */ rsize_t;
 
errno_t asctime_s(char* s, rsize_t maxsize, const struct tm* timeptr);
errno_t ctime_s(char* s, rsize_t maxsize, const time_t* timer);
struct tm* gmtime_s(const time_t* restrict timer, struct tm* restrict result);
struct tm* localtime_s(const time_t* restrict timer, struct tm* restrict result);
#endif