【问题标题】:using to_iso_extended_string with boost date将 to_iso_extended_string 与提升日期一起使用
【发布时间】:2011-09-01 04:42:24
【问题描述】:

我正在尝试将 d2 转换为“2011-08-02”形式的字符串,以便将其传递给我的 sql 语句。根据 boost 站点, to_iso_extended_string 应该返回该格式,但我得到以下内容:'2011-Aug-02'。

date today(day_clock::local_day());
date_duration dd(30);
date d2=today-dd;
std::string to_iso_extended_string(date d2);

那么如何将日期转换为 yyyy-mm-dd 格式的字符串。

【问题讨论】:

  • 修复您的测试代码。它坏了。

标签: c++ boost boost-date-time


【解决方案1】:

我刚刚对此进行了测试,它为我打印了2011-08-02

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

namespace bg = boost::gregorian;

int
main ()
{
    bg::date today (bg::day_clock::local_day());
    bg::date_duration dd(30);
    bg::date d2 = today - dd;
    std::string str(to_iso_extended_string(d2));
    std::cout << str << "\n";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-22
    • 2021-08-31
    • 2017-02-08
    • 2021-10-01
    • 2019-12-17
    • 2012-01-05
    • 1970-01-01
    相关资源
    最近更新 更多