简单的问题,如何使用尽可能少的代码将 std::chrono::time_point
正确转换为 std::string
?
注意:我不想将 cout
与 put_time()
一起使用。接受 C++11 和 C++14 解决方案。
最佳答案
仅使用标准库头文件(适用于 >= C++11):
#include <ctime>
#include <chrono>
#include <string>
using sc = std::chrono::system_clock ;
std::time_t t = sc::to_time_t(sc::now());
char buf[20];
strftime(buf, 20, "%d.%m.%Y %H:%M:%S", localtime(&t));
std::string s(buf);
关于c++ - 将 time_point 转换为字符串的最漂亮方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48217017/