std::chrono::system_clock::from_time_t
From cppreference.com
 
 
 < cpp | chrono | system clock 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Date and time library 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
(C++11)
(C++20)
  (C++20)
(C++11)
(C++11)
(C++11)
(C++20)
(C++20)
(C++20)
(C++11)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
  (C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
std::chrono::system_clock 
 
 Member functions
system_clock::from_time_t
 Time point I/O
static std::chrono::system_clock::time_point from_time_t( std::time_t t ) noexcept;
 
 (since C++11) 
Converts t to a time point type, using the coarser precision of the two types.
If time_point has lower precision, it is implementation defined whether the value is rounded or truncated.
Contents
[edit] Parameters
 t
 -
 std::time_t  value to convert
[edit] Return value
A value of type std::chrono::system_clock::time_point representing t.
[edit] Example
Run this code
#include <chrono> #include <ctime> #include <iostream> #include <thread> int main() { using namespace std::chrono_literals; const std::time_t t = std::time (nullptr); // usually has "1 second" precision const auto from = std::chrono::system_clock::from_time_t(t); std::this_thread::sleep_for (500ms); const auto diff = std::chrono::system_clock::now () - from; std::cout << diff << " (" << std::chrono::round <std::chrono::milliseconds >(diff) << ")\n"; }
Possible output:
987654321ns (987ms)