使用to_iso_extended_string与boost日期

using to_iso_extended_string with boost date

本文关键字:boost string 日期 extended to iso 使用      更新时间:2023-10-16

我正试图将d2转换为形式'2011-08-02'的字符串,因此我可以将其传递给我的sql语句。根据boost站点,to_iso_extended_string应该返回该格式,但我得到的却是以下内容:' 2011-08-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格式的字符串

我刚刚测试了这个,它为我打印了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";
}
相关文章: