命名空间
变体
操作

标准库头文件 <ctime>

来自 cppreference.cn
< cpp‎ | 头文件
 
 
标准库头文件
算法
<algorithm>
<numeric>
字符串
<cctype>
<cstring>
<cuchar> (C++11)
<cwchar>
<cwctype>
<string_view> (C++17)
<string>
文本处理
<clocale>
<codecvt> (C++11/17/26*)
<locale>
<regex> (C++11)
<text_encoding> (C++26)   
数值
<cfenv> (C++11)
<cmath>
<complex>
<linalg> (C++26)
<numbers> (C++20)
<random> (C++11)
<simd> (C++26)
<valarray>
时间
<chrono> (C++11)
<ctime>
C 兼容性
<ccomplex> (C++11/17/20*)
<ciso646> (直到 C++20)
<cstdalign> (C++11/17/20*)
<cstdbool> (C++11/17/20*)
<ctgmath> (C++11/17/20*)
 

此头文件最初在 C 标准库中为 <time.h>

此头文件是 C 风格日期和时间库的一部分。

目录

宏常量

每秒的处理器时钟节拍数
(宏常量) [编辑]
实现定义的空指针常量
(宏常量) [编辑]

类型

进程运行时间
(typedef) [编辑]
sizeof 运算符返回的无符号整型
(typedef) [编辑]
自纪元以来的时间类型
(typedef) [编辑]
日历时间类型
(类) [编辑]
(C++17)
秒和纳秒时间
(结构体)[编辑]

函数

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

[编辑] 概要

#define NULL /* see description */
#define CLOCKS_PER_SEC /* see description */
#define TIME_UTC /* see description */
 
namespace std {
  using size_t = /* see description */;
  using clock_t = /* see description */;
  using time_t = /* see description */;
 
  struct timespec;
  struct tm;
 
  clock_t clock();
  double difftime(time_t time1, time_t time0);
  time_t mktime(tm* timeptr);
  time_t time(time_t* timer);
  int timespec_get(timespec* ts, int base);
  char* asctime(const tm* timeptr);
  char* ctime(const time_t* timer);
  tm* gmtime(const time_t* timer);
  tm* localtime(const time_t* timer);
  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;
};