使用分数和时区生成完整的iso日期时间表示字符串

问题描述 投票:2回答:1

我想打印符合ISO 8601标准的字符串,其形式为完整的日期时间表示,如ISO中所示

4.3.2完整表示

1985-04-12T10:15:30Z结合

4.2.2.4带小数部分的表示法

如23:20:50,5

合并允许的

4.3.3除完成外的表示

形式为19850412T101530,42 + 04或1985-04-12T10:15:30.32Z

使用当前(挂钟)的提升日期时间,但我甚至不知道如何使用boost文档打印当前时间的简单日期时间字符串。

c++ datetime boost iso8601
1个回答
0
投票

你说你想打印“当前(挂钟)”,但你的例子说“1985”?...

以下将以ISO格式打印当前时间:

#include <iostream>
#include <boost/date_time.hpp>

int main()
{
    auto now = boost::posix_time::microsec_clock::universal_time();

    std::cout << to_iso_extended_string(now) << std::endl;
}

输出:

2019-04-26T07:52:34.533296

注意:ISO时间始终为UTC时区,因此您只需将“Z”(Zulu)后缀附加到其上即可。

有关更多详细信息,请参阅Posix_time documentation

© www.soinside.com 2019 - 2024. All rights reserved.