将ptime转换为std::string

Convert ptime to std::string

本文关键字:string std ptime 转换      更新时间:2023-10-16

如何将boost ptime转换为std字符串?我尝试了多种方法,我得到编译时错误。但根据boost的说法,这应该是可能的。

std::string function()
{
    now = boost::posix_time::second_clock::local_time();
    return std::string(now);
}

下面是一个简单的工作示例

查看Live On Coliru

#include "boost/date_time/posix_time/time_formatters_limited.hpp" 
int main()
{
    using namespace boost::posix_time;
    ptime now = second_clock::local_time();
    std::cout << to_simple_string(now) << std::endl;
}