名稱空間
變體
操作

標準庫標頭檔案 <ctime>

來自 cppreference.com
 
 
標準庫標頭檔案
演算法
<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;
};