First time here? Check out the FAQ!


ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
3

Conversion from ROS timestamp to ISO-8601 time format

asked Jan 14 '17

Fairf4x gravatar image

I would like to convert a ROS timestamp like this:

ros::Time stamp = ros::Time::now();

to string in ISO-8601 format.

The best resource I was able to google up so far is this topic:

http://stackoverflow.com/questions/79...

Is there by any chance any function in ROS I can use instead of coding my own convertor?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
5

answered Jan 14 '17

spmaniato gravatar image

updated Jan 14 '17

Something like this should work:

#include "boost/date_time/posix_time/posix_time.hpp"

boost::posix_time::ptime my_posix_time = ros::Time::now().toBoost();
std::string iso_time_str = boost::posix_time::to_iso_extended_string(my_posix_time)

Is it the ISO you are looking for? (Didn't test so please double-check syntax and result)

Reference: http://www.boost.org/doc/libs/1_63_0/...

Preview: (hide)
2

answered Jan 17 '17

Fairf4x gravatar image

I tested the code and it works as it is.

Later I found out, that the string compliant with ISO-8601 can represent time with various precision.

Anyway the output I got from the ROS timestamp using the function:

boost::posix_time::to_iso_extended_string(my_posix_time)

looked like this:

iso_time_str = 2017-01-17T21:02:40.289279

I needed only seconds so I am happy with the result. Thank you for quick answer.

Preview: (hide)

Question Tools

2 followers

Stats

Asked: Jan 14 '17

Seen: 11,211 times

Last updated: Jan 17 '17