# C 语言标准库头文件 time.h
这个头文件提供 线程 相关的功能。例如线程控制、互斥量、条件变量、线程局部存储等。
# 常量
| 宏 |
标准 |
说明 |
CLOCKS_PER_SEC |
C89 |
处理器的每秒时钟数,POSIX 上定义为 1000000 而非实际的时钟数 |
TIME_UTC |
C11 |
表示时间基准为 UTC 时间 |
# 类型
| 类型 |
标准 |
说明 |
time_t |
C89 |
日历时间的时间戳类型(自 1970 年 1 月 1 日 00:00:00.000 UTC 以来的秒数) |
clock_t |
C89 |
处理器时钟类型 |
| tm |
C89 |
日历时间类型 |
| timespec |
C11 |
包含秒和纳秒的结构 |
# 函数
| 格式转换 |
标准 |
说明 |
| strftime |
C89 |
将日历时间从结构体 tm 转换为自定义的文本形式 |
| asctime |
C89(在 C23 废弃) |
将日历时间从结构体 tm 转换为文本形式 |
| asctime_s |
C11 |
将日历时间从结构体 tm 转换为文本形式 |
| ctime |
C89(在 C23 废弃) |
将日历时间从时间戳 time_t 转换为文本形式 |
| ctime_s |
C11 |
将日历时间从时间戳 time_t 转换为文本形式 |
| mktime |
C89 |
将日历时间从本地时间的结构体 tm 转换为时间戳 time_t |
| gmtime |
C89 |
将日历时间从时间戳 time_t 转换为 UTC 时间的结构体 tm |
| gmtime_s |
C11 |
将日历时间从时间戳 time_t 转换为 UTC 时间的结构体 tm |
| gmtime_r |
C23 |
将日历时间从时间戳 time_t 转换为 UTC 时间的结构体 tm |
| localtime |
C89 |
将日历时间从时间戳 time_t 转换为本地时间的结构体 tm |
| localtime_s |
C11 |
将日历时间从时间戳 time_t 转换为本地时间的结构体 tm |
| localtime_r |
C23 |
将日历时间从时间戳 time_t 转换为本地时间的结构体 tm |
graph LR
utc[UTC 时间结构体 tm] -- strftime --> text[文本]
local[本地时间结构体 tm] -- strftime --> text
local -- mktime --> time_t[时间戳 time_t]
time_t -- gmtime --> utc
time_t -- localtime --> local
# 推荐阅读
本文 更新于: 2025-11-27 09:38:07 创建于: 2025-11-27 09:38:07