I have a device which gives me boost::posix_time::ptime thorugh its API. To sychronize with other Data I need the time as NTP timestamp, differentiated in NTP seconds and NTP fract_seconds.
I tried something like:
#include "boost/date_time/posix_time/posix_time.hpp"
#include <iostream>
using namespace std;
using boost::posix_time::ptime;
using boost::posix_time::time_duration;
using boost::gregorian::date;
int main()
{
ptime t = boost::posix_time::microsec_clock::local_time();
ptime myEpoch(date(1900,boost::gregorian::Jan,1));
time_duration myTimeFromEpoch = t - myEpoch;
boost::uint64_t myTimeAsInt = myTimeFromEpoch.ticks();
cout << myTimeAsInt << endl;
boost::uint32_t seconds = (boost::uint32_t)((myTimeAsInt >> 32) & 0xFFFFFFFF);
boost::uint32_t fraction = (boost::uint32_t)(myTimeAsInt & 0xFFFFFFFF);
cout << seconds << endl;
cout << fraction << endl;
return 0;
}
But it does not give me the correct results? Any help appreciated.