【发布时间】:2020-07-07 10:27:11
【问题描述】:
我有以下代码,使用日期库:
#include "date.h"
#include <iostream>
#include <sstream>
using namespace date;
using namespace std::chrono;
int main()
{
auto now = system_clock::now();
std::stringstream ss;
ss << now;
std::string nowStr = ss.str(); // I need a string
std::cout << nowStr << " UTC\n";
}
结果是:
2020-03-26 17:38:24.473372486 UTC
stringstream 是从 now() 返回的 chrono::timepoint 获取字符串的正确方法吗?如果是这样,我如何将这些纳秒四舍五入到毫秒?
【问题讨论】:
标签: c++ date c++11 time chrono