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

Converting ros::Time to C++ string

asked 2019-11-07 20:33:26 -0500

zlg9 gravatar image

How can we convert the result of ros::Time::now() into std::string, given that std::string to_string (*) in C++11 doesn't support this conversion ?

edit retag flag offensive close merge delete

Comments

Answer to convert to a formatted date time string using boost::posix_time::to_iso_extended_string#q251966

lucasw gravatar image lucasw  ( 2021-07-14 13:16:54 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2019-11-07 21:31:38 -0500

Thomas D gravatar image

You probably want to use the ros::Time::now().toSec() result, which is a double.

http://docs.ros.org/latest/api/rostim...

Then you can convert that double to a string with std::string to_string.

You could use strftime to convert the double to many different string formats as well.

http://www.cplusplus.com/reference/ct...

edit flag offensive delete link more

Comments

Yes, that's what I needed. Thanks

zlg9 gravatar image zlg9  ( 2019-11-08 13:00:02 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2019-11-07 20:33:26 -0500

Seen: 4,892 times

Last updated: Nov 07 '19