yo/namespaces/chrono/examples/puttime.cc
raw| 1 | #include <iostream> |
| 2 | #include <chrono> |
| 3 | |
| 4 | using namespace std; |
| 5 | using namespace chrono; |
| 6 | |
| 7 | //demo |
| 8 | int main() |
| 9 | { |
| 10 | auto now = system_clock::now(); // get a time_point |
| 11 | cout << now << '\n'; // now's UTC time |
| 12 | // convert to a time_t |
| 13 | time_t timeT = system_clock::to_time_t(now); |
| 14 | tm *local = localtime(&timeT); // get a tm * |
| 15 | cout << put_time(local, "%c") << '\n'; // show the time |
| 16 | } |
| 17 | //= |