标准库标头 <ctime>

来自cppreference.com
< cpp‎ | header


 
 
标准库头
通用工具
<any> (C++17)
<bitset>
<bit> (C++20)
<charconv> (C++17)
<expected> (C++23)
<format> (C++20)
<functional>
<optional> (C++17)
<stdbit.h> (C++26)
<tuple> (C++11)
<typeindex> (C++11)
<utility>
<variant> (C++17)
容器
<array> (C++11)
<deque>
<flat_map> (C++23)
<flat_set> (C++23)
<forward_list> (C++11)
<hive> (C++26)
<inplace_vector> (C++26)   
<list>
<map>
<mdspan> (C++23)
<queue>
<set>
<span> (C++20)
<stack>
<unordered_map> (C++11)
<unordered_set> (C++11)
<vector>
迭代器
<iterator>
范围
<generator> (C++23)
<ranges> (C++20)
算法
<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)   
cpp/header#数值库数值
<cfenv> (C++11)
<cmath>
<complex>
<linalg> (C++26)
<numbers> (C++20)
<random> (C++11)
<simd> (C++26)
<stdckdint.h> (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*)
 

此标头原作为 <time.h> 存在于 C 标准库。

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

宏常量

每秒的处理器始时钟计次数
(宏常量)
实现定义的空指针常量
(宏常量)

类型

进程运行时间
(typedef)
sizeof 运算符返回的无符号整数类型
(typedef)
从纪元起的时间类型
(typedef)
日历时间类型
(类)
(C++17)
以秒和纳秒表示的时间
(结构体)

函数

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

概要

#define NULL /* 见描述 */
#define CLOCKS_PER_SEC /* 见描述 */
#define TIME_UTC /* 见描述 */
 
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 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;
};