How to get GMT time in milliseconds using boost Date_Time?

Is there an easy way to get boost Date_Timethe current time GMTin milliseconds from the library ?

Here is one example that uses time_of_day, I don't want time_of_day, but the total time in GMT is like 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();
+5
source share
1 answer

There is nothing built-in that I can see, but, as usual, 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();
}
+7
source

All Articles