Ask Your Question

Conversion from ROS timestamp to ISO-8601 time format

asked 2017-01-14 15:32:21 -0600

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:

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

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-01-14 16:56:26 -0600

spmaniato gravatar image

updated 2017-01-14 16:58:35 -0600

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)


edit flag offensive delete link more

answered 2017-01-17 15:16:19 -0600

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:


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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2017-01-14 15:32:21 -0600

Seen: 7,577 times

Last updated: Jan 17 '17