How to convert std::chrono::time_point to calendar datetime string with fractional seconds?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How to convert std::chrono::time_point to calendar datetime string with fractional seconds? For example: "10-10-2012 12:38:40.123456". 回答1: If system_clock, this class have time_t conversion. #include #include #include using namespace std::chrono; int main() { system_clock::time_point p = system_clock::now(); std::time_t t = system_clock::to_time_t(p); std::cout example result: Thu Oct 11 19:10:24 2012 EDIT: But, time_t does not contain fractional seconds. Alternative way is to use time_point::time_since_epoch() function. This function