Ask Your Question
1

Conversion from ROS timestamp to ISO-8601 time format

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

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?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

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

spmaniato gravatar image

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

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/...

edit flag offensive delete link more
1

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

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.

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

2 followers

Stats

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

Seen: 4,808 times

Last updated: Jan 17 '17