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();
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With