How to get the system time in C++11

Output: 2018-02-18 08:13:27

Code:

#include <iostream>
#include <iomanip>
#include <chrono>

int main() {

		std::chrono::system_clock::time_point tp = std::chrono::system_clock::now();
		std::time_t time = std::chrono::system_clock::to_time_t(tp);
		std::cout << std::put_time(std::localtime(&time), "%F %T") << '\n';
}

Credits to cppreference

Bookmark the permalink.