4874

24 分钟

#C 语言标准库头文件 time.h

这个头文件提供 线程 相关的功能。例如线程控制、互斥量、条件变量、线程局部存储等。

#常量

标准说明
CLOCKS_PER_SECC89处理器的每秒时钟数,POSIX 上定义为 1000000 而非实际的时钟数
TIME_UTCC11表示时间基准为 UTC 时间

#类型

类型标准说明
time_tC89日历时间的时间戳类型(自 1970 年 1 月 1 日 00:00:00.000 UTC 以来的秒数)
clock_tC89处理器时钟类型
tmC89日历时间类型
timespecC11包含秒和纳秒的结构

#函数

时间操作标准说明
difftimeC89计算时间差
timeC89获取当前时间戳
clockC89获取程序启动以来经过的处理器时钟数
timespec_getC11根据给定的时间基准返回以秒和纳秒为单位的日历时间
timespec_getresC23返回基于给定时间基准的日历时间分辨率
格式转换标准说明
strftimeC89将日历时间从结构体 tm 转换为自定义的文本形式
asctimeC89(在 C23 废弃)将日历时间从结构体 tm 转换为文本形式
asctime_sC11将日历时间从结构体 tm 转换为文本形式
ctimeC89(在 C23 废弃)将日历时间从时间戳 time_t 转换为文本形式
ctime_sC11将日历时间从时间戳 time_t 转换为文本形式
mktimeC89将日历时间从本地时间的结构体 tm 转换为时间戳 time_t
gmtimeC89将日历时间从时间戳 time_t 转换为 UTC 时间的结构体 tm
gmtime_sC11将日历时间从时间戳 time_t 转换为 UTC 时间的结构体 tm
gmtime_rC23将日历时间从时间戳 time_t 转换为 UTC 时间的结构体 tm
localtimeC89将日历时间从时间戳 time_t 转换为本地时间的结构体 tm
localtime_sC11将日历时间从时间戳 time_t 转换为本地时间的结构体 tm
localtime_rC23将日历时间从时间戳 time_t 转换为本地时间的结构体 tm

strftime

strftime

mktime

gmtime

localtime

UTC 时间结构体 tm

文本

本地时间结构体 tm

时间戳 time_t

#推荐阅读

创建于 2025/10/10

更新于 2025/10/16