Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert timestamp (in milliseconds) to boost ptime

I need to convert the a time measured in milliseconds since the epoch to a boost::posix_time::ptime. The only function I see is to convert is from_time_t but that is only in seconds and would lose the milliseconds.

How can I convert from milliseconds since epoch to a ptime type?

like image 857
edA-qa mort-ora-y Avatar asked Nov 29 '22 02:11

edA-qa mort-ora-y


1 Answers

Where ms is your milliseconds count since the epoch:

ptime epoch_milliseconds_to_ptime(unsigned long int ms)
{
  static const ptime epoch(date(1970, 1, 1));

  return epoch + milliseconds(ms);
}
like image 169
ereOn Avatar answered Dec 06 '22 21:12

ereOn