I\'m struggling to figure out how to preform a conversion with boost::date_time. I want to convert a millisecond value measured from the Unix epoch (00:00, Jan 1, 1970) to a hu
time_t
is usually seconds since "the epoch", rather than milliseconds.
If you dont care about milliseconds you should be able to do this:
std::time_t tt = static_cast<time_t>(ticksFromEpoch/1000)
If you do care about milliseconds you can either add them back in at the end (which is tricky to get right for times like 12:00:00.001 AM )
Or you'll need to go another route. You may need to use something like this: (untested)
boost::posix_time::ptime t2(
boost::gregorian::date(1970,boost::date_time::Jan,1), //The epoch
boost::posix_time::seconds( ticksFromEpoch / 1000 ) + // Number of seconds
boost::posix_time::milliseconds( ticksFromEpoch % 1000) // And the micros too.
);