How can I create a boost::local_time::local_date_time
object from a tm
time structure?
views:
368answers:
2
+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
2009-07-31 15:32:22
Unfortunately this hard codes the timezone
Richard
2009-07-31 16:06:31