|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
system_clock::to_time_t | ||||
| Time point I/O | ||||
staticstd::time_t to_time_t(const time_point& t)noexcept; | (since C++11) | |
Convertst to astd::time_t type.
Ifstd::time_t has lower precision, it is implementation-defined whether the value is rounded or truncated.
Contents |
| t | - | system clock time point to convert |
Astd::time_t value representingt.
Get the current time as astd::time_t two ways.
#include <chrono>#include <ctime>#include <iostream>#include <thread>usingnamespace std::chrono_literals; int main(){// The old waystd::time_t oldt=std::time({}); std::this_thread::sleep_for(2700ms); // The new wayautoconst 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";}
Possible output:
newt - oldt == 3 s
[static] | convertsstd::time_t to a system clock time point (public static member function)[edit] |