Reputation: 1892
I am doing the follows
using namespace boost::posix_time;
ptime epoch = time_from_string("1970-01-01 00:00:00.000");
ptime other = time_from_string("2011-08-09 17:27:00.000.000");
time_duration const diff = other - epoch;
long long ms = diff.total_microseconds();
cout<<"diff is"<<ms<<endl;
The echo I get is diff is 1312910820000000
Then when I change the ptime other to
ptime other = time_from_string("2011-08-09 17:27:00.000.100");
And I get the same echo, why?
Upvotes: 1
Views: 1303
Reputation: 392883
The format is incorrect, you had too many .
separators: Live On Coliru
#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
int main()
{
using namespace boost::posix_time;
ptime epoch = from_time_t(0);
ptime other = time_from_string("2011-08-09 17:27:00.000000");
std::cout << "diff is " << (other - epoch).total_microseconds() << std::endl;
other = time_from_string("2011-08-09 17:27:00.00001");
std::cout << "diff is " << (other - epoch).total_microseconds() << std::endl;
}
Prints
diff is 1312910820000000
diff is 1312910820000010
Upvotes: 3