命名空间
变体
操作

标准库头文件 <ctime>

来自 cppreference.cn
< cpp‎ | header
 
 
标准库头文件
算法
<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 风格日期和时间库的一部分。

目录

宏常量

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

类型

进程运行时间
(类型定义) [编辑]
sizeof 运算符返回的无符号整数类型
(类型定义) [编辑]
自纪元起的时间类型
(类型定义) [编辑]
日历时间类型
(类) [编辑]
(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;
};