[ros-users] ros::time to boost::posix_time::ptime

Markus Bader markus.bader at tuwien.ac.at
Tue Jan 24 09:04:05 UTC 2012


Thanks to Lorenz and William for the quick answer
It would be nice to enhance the code for a back conversion back to
ros::Time who is in charge for that?
The downside would be that the resolution will be reduced if boost
time is compiled for six fraction digits (mirosec).

void fromBoost ( const boost::posix_time::ptime &src, ros::Time &des ) const {
    boost::posix_time::time_duration diff = src -
    des.sec = diff.total_seconds();
    des.nsec = diff.fractional_seconds();
    #warning boost time uses only microseconds nanoseconds are lost
    des.nsec = diff.fractional_seconds()*1000;

More information about the ros-users mailing list