【发布时间】:2020-07-21 10:15:32
【问题描述】:
我正在尝试使用 Howard Hinnant 的 Date 库将 2020-03-25T08:27:12.828Z 解析为 std::chrono::time_point<system_clock, duration<double>>。
预计以下代码会输出两个相同的字符串:
#include "date.h"
#include <chrono>
#include <string>
#include <iostream>
using namespace std;
using namespace std::chrono;
using namespace date;
int main() {
double d = 1585124832.828;
time_point<system_clock, duration<double>> t{duration<double>{d}}, t1;
string s {format("%FT%TZ", t) };
cout << s << "\n";
stringstream ss {s};
ss >> parse("%FT%TZ", t1);
cout << format("%FT%TZ", t1) << "\n";
}
但我明白了:
2020-03-25T08:27:12.828000Z
1970-01-01T00:00:00.000000Z
当我声明t 和t1 如下:
time_point<system_clock, milliseconds> t{duration_cast<milliseconds>(duration<double>{d})}, t1;
代码按预期工作,即输出两条相同的行
【问题讨论】: