M
Mark
I want to simply get the unix style epoch time
(number of secs to now from Jan 01, 1970 UTC) for
use as a timestamp to track the staleness of some
objects. So I don't care about time zones or whatever
as long as it's consistent. So I picked the epoch time
UTC getting the value I wanted, "timestamp", this way:
#include "boost/date_time/local_time/local_time.hpp"
using namespace boost::gregorian;
using namespace boost::local_time;
using namespace boost:osix_time;
namespace {
const ptime EPOCH(date(1970,1,1));
}
void
somefunc()
{
const ptime cur_time(second_clock::universal_time());
const unsigned int timestamp = (cur_time - EPOCH).total_seconds();
......
}
but I'd prefer a way that doesn't need the time_duration value (the cur_time - EPOCH)
and the EPOCH and the "total_seconds" call. I'd have thought there'd be so much
use for epoch time in seconds that there's be a prerolled function for this
in boost::date_time but I'm not seeing it. Is the above about as simple as it
gets with boost::date_time for this?
Mark
(number of secs to now from Jan 01, 1970 UTC) for
use as a timestamp to track the staleness of some
objects. So I don't care about time zones or whatever
as long as it's consistent. So I picked the epoch time
UTC getting the value I wanted, "timestamp", this way:
#include "boost/date_time/local_time/local_time.hpp"
using namespace boost::gregorian;
using namespace boost::local_time;
using namespace boost:osix_time;
namespace {
const ptime EPOCH(date(1970,1,1));
}
void
somefunc()
{
const ptime cur_time(second_clock::universal_time());
const unsigned int timestamp = (cur_time - EPOCH).total_seconds();
......
}
but I'd prefer a way that doesn't need the time_duration value (the cur_time - EPOCH)
and the EPOCH and the "total_seconds" call. I'd have thought there'd be so much
use for epoch time in seconds that there's be a prerolled function for this
in boost::date_time but I'm not seeing it. Is the above about as simple as it
gets with boost::date_time for this?
Mark