Here's an example adapted from cppreference.com :
#include <iostream>
#include <iomanip>
#include <ctime>
#include <chrono>
int main() {
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
std::time_t now_c = std::chrono::system_clock::to_time_t(now);
std::cout << "The time was just "
<< std::put_time(std::localtime(&now_c), "%F %T") << '\n';
}
I don't like this. I want to print my time point without having to go through time_t
. Can I do so...:
- at all?
- with an arbitrary format like
put_time
supports?
Notes:
- Standard library solutions are best; non-standard but robust solutions are also relevant.
- Not a dupe of this - since I'm also interested in arbitrary format printing; but it should be noted that @HowardHinnant's answer to that one resolves the first part of this one.