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

Converting ros::Time to C++ string

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

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


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 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

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

Thomas D gravatar image

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

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.

edit flag offensive delete link more


Yes, that's what I needed. Thanks

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

Question Tools



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

Seen: 4,688 times

Last updated: Nov 07 '19