c++ - 带有 to_iso_extended_string 的当前 UTC 日期字符串,格式为毫秒
问题描述
我想以毫秒精度生成当前的 UTC 日期时间,但我只能以秒或微秒精度获得它。是否有可能以毫秒精度获得它?
std::cout << to_iso_extended_string(microsec_clock::universal_time()) + "Z" << std::endl;
"2020-02-27T13:05:46.543801Z"
std::cout << to_iso_extended_string(second_clock::universal_time()) + "Z" << std::endl;
"2020-02-27T13:11:00Z"
预期格式:
"2020-02-27T13:05:46.543Z"
解决方案
我认为您可以从微秒版本中获取子字符串。
就像是:
std::string microsec_time = to_iso_extended_string(microsec_clock::universal_time());
std::string millisec_time = microsec_time.substr(0, microsec_time.size()-3);
std::cout << millisec_time << 'Z' << std::endl;
它应该给你你期望的输出。
推荐阅读
- tableau-api - 离散列的总计
- android - 如何重用 Exoplayer 实例并将相同的实例附加到视图?
- json - Json 意想不到的角色 
- python - Python - 打印接下来的 5 天,不包括周一和周日
- c - 两组 ASCII 字符之间的映射
- mysql - 将 .sql 文件附加到现有数据库
- android - 谷歌地图在笔记本电脑上渲染,而不是在离子应用程序中的移动设备上
- java - 如何使用 Java 获取使用 HTML 输入文件上传的文件的内容?
- python - 无法使用 pyusb 写入 USB 设备(收到超时错误)
- sql - 如何在 PostgreSQL 中更新或插入