std::chrono::system_clock::to_time_t
來自 cppreference.com
< cpp | chrono | system_clock
static std::time_t to_time_t( const time_point& t ) noexcept; |
(C++11 起) | |
將 t 轉換為 std::time_t 型別。
若 std::time_t 精度較低,則實現定義值是舍入還是截斷。
目錄 |
[編輯] 引數
t | - | 要轉換的系統時鐘時間點 |
[編輯] 返回值
表示 t 的 std::time_t 值。
[編輯] 示例
以兩種方式獲取當前時間為 std::time_t。
執行此程式碼
#include <chrono> #include <ctime> #include <iostream> #include <thread> using namespace std::chrono_literals; int main() { // The old way std::time_t oldt = std::time({}); std::this_thread::sleep_for(2700ms); // The new way auto const now = std::chrono::system_clock::now(); std::time_t newt = std::chrono::system_clock::to_time_t(now); std::cout << "newt - oldt == " << newt - oldt << " s\n"; }
可能的輸出
newt - oldt == 3 s
[編輯] 參閱
[靜態] |
將 std::time_t 轉換為系統時鐘時間點 (public static member function) |