Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get GMT time in milliseconds using boost Date_Time?

Is there a simple way to get from boost Date_Time library a current GMT time in milliseconds?

Here is one example which uses time_of_day, I don't want time_of_day but total time in GMT as long long int:

boost::posix_time::ptime time =
          boost::posix_time::microsec_clock::universal_time();
boost::posix_time::time_duration duration( time.time_of_day() );  // ???
long long int timeInMilliseconds = duration.total_milliseconds();
like image 885
stefanB Avatar asked Jun 22 '11 12:06

stefanB


1 Answers

There's nothing built-in that I can see, but as usual, it's trivial to implement:

boost::posix_time::time_duration::tick_type milliseconds_since_epoch()
{
    using boost::gregorian::date;
    using boost::posix_time::ptime;
    using boost::posix_time::microsec_clock;

    static ptime const epoch(date(1970, 1, 1));
    return (microsec_clock::universal_time() - epoch).total_milliseconds();
}
like image 82
ildjarn Avatar answered Oct 24 '22 18:10

ildjarn