标准库标头 <ctime>
来自cppreference.com
此标头原作为 <time.h> 存在于 C 标准库。
此头文件是 C 风格日期和时间库的一部分。
宏常量 | |
| 每秒的处理器始时钟计次数 (宏常量) | |
| 由实现定义的空指针常量 (宏常量) | |
类型 | |
| 进程运行时间 (typedef) | |
| sizeof 运算符返回的无符号整数类型 (typedef) | |
| 从纪元起的时间类型 (typedef) | |
| 日历时间类型 (类) | |
(C++17) |
以秒和纳秒表示的时间 (结构体) |
函数 | |
时间操作 | |
| 返回自程序启动时起的原始处理器时钟时间 (函数) | |
| 返回自纪元起计的系统当前时间 (函数) | |
| 计算时间之间的差 (函数) | |
(C++17) |
返回基于给定时间基底的以秒和纳秒计的日历时间 (函数) |
(C++26) |
返回基于给定时间基底的日历时间分辨率 (函数) |
格式转换 | |
(C++26 弃用) |
将 std::tm 对象转换成文本表示 (函数) |
(C++26 弃用) |
将 std::time_t 对象转换成文本表示 (函数) |
| 将 std::tm 对象转换成自定义的文本表示 (函数) | |
(C++26) |
将纪元起时间转换成以协调世界时表示的日历时间 (函数) |
(C++26) |
将纪元起时间转换成以本地时间表示的日历时间 (函数) |
| 将日历时间转换成纪元开始经过的时间 (函数) | |
(C++26) |
将日历时间转换成纪元开始经过的时间,忽略夏时令标志 (函数) |
概要
#define __STDC_VERSION_TIME_H__ 202311L
#define NULL /* 由实现定义 */
#define CLOCKS_PER_SEC /* 见描述 */
#define TIME_UTC /* 见描述 */
#define TIME_MONOTONIC /* 见描述 */ // 可选
#define TIME_ACTIVE /* 见描述 */ // 可选
#define TIME_THREAD_ACTIVE /* 见描述 */ // 可选
namespace std {
using size_t = /* 由实现定义 */;
using clock_t = /* 见描述 */;
using time_t = /* 见描述 */;
struct timespec;
struct tm;
clock_t clock();
double difftime(time_t time1, time_t time0);
time_t mktime(tm* timeptr);
time_t timegm(tm* timeptr);
time_t time(time_t* timer);
int timespec_get(timespec* ts, int base);
int timespec_getres(timespec* ts, int base);
// char* asctime(const tm* timeptr);
// char* ctime(const time_t* timer);
tm* gmtime(const time_t* timer);
tm* gmtime_r(const time_t* timer, tm* buf);
tm* localtime(const time_t* timer);
tm* localtime_r(const time_t* timer, tm* buf);
size_t strftime(char* s, size_t maxsize, const char* format, const tm* timeptr);
}
类 std::timespec
struct timespec {
std::time_t tv_sec;
long tv_nsec;
};
类 std::tm
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};