我使用以下行来获取毫秒精度的时间:
std::stringstream s;
std::chrono::time_point<std::chrono::utc_clock> TimeTag = time_point_cast<std::chrono::milliseconds>(std::chrono::utc_clock::now());
s << format("{0:%F}T{0:%TZ}", TimeTag);
当我将其写入文件时,输出为(ns 精度):
2024-01-07T17:02:50.214000000Z
如何格式化而不带尾随 0?
谢谢, 约翰内斯
WWW 上的每个相关网站都告诉我使用上述说明,但结果总是带有尾随 0。
使用
std::chrono::time_point<std::chrono::utc_clock, std::chrono::milliseconds>
(或在示例中仅使用 auto
)作为 TimeTag
类型。