如何从 boost::local_time::local_date_time 时间结构创建 tm 对象?

最佳答案

有点痛苦,但似乎您必须通过 posix_time::ptime :

using namespace boost;
time_t rawtime;
time(&rawtime);
struct tm* timeinfo = localtime(&rawtime);
posix_time::ptime my_ptime = posix_time::ptime_from_tm(*timeinfo);
local_time::time_zone_ptr zone(new local_time::posix_time_zone("GMT"));
local_time::local_date_time my_ldt(my_ptime, zone);
std::cout << "local_date_time: " << my_ldt << std::endl;

关于c++ - 将 tm 结构转换为 boost::local_time::local_date_time,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1212152/

10-12 21:42