tags:

views:

368

answers:

2

How can I create a boost::local_time::local_date_time object from a tm time structure?

+1  A: 

This will help you to convert tm structure into posix_time object. Look around for more conversions.

ARV
+1  A: 

Bit of a pain, but it seems like you have to go via 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;
mash
Unfortunately this hard codes the timezone
Richard