【问题标题】:date-time string to boost::gregorian::dateboost::gregorian::date 的日期时间字符串
【发布时间】:2010-11-26 14:38:58
【问题描述】:

我有以下 std::string '2010-08-10T23:59:00' 我需要将其转换为 boost::gregorian::date 对象。

我知道我应该使用boost::date_time::date_input_facet,但我似乎不知道该怎么做。

有人可以帮助我如何进行这种转换吗?

【问题讨论】:

    标签: c++ string datetime


    【解决方案1】:

    boost 的 posix_time 模块支持从该格式直接转换(除非我很困惑,否则它是 ISO 时间格式?)。看看:

    boost::posix_time::from_iso_string
    

    你只需要先去掉格式标记。

    posix_time::time_from_string
    

    也可能对你有用。

    您应该能够将 posix_time 转换为 gregorian。

    希望这会有所帮助。

    【讨论】:

    • from_iso_string 需要 YYYYMMDD 格式,而不是 YYYY-MM-DD 格式。
    • @quant_dev 已经有一段时间了,但我想我已经用“你需要先去除格式掩码”来介绍这一点
    猜你喜欢
    • 1970-01-01
    • 2016-10-26
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多