Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi ros::Time are sec and nsec since epoch

 #include <iostream>
 #include <chrono>
 #include <ctime>
 #include <ros/ros.h>

int main()
{
   const auto p3 = std::chrono::high_resolution_clock::now();

   std::chrono::duration tstamp = p3.time_since_epoch();
   int32_t sec = std::chrono::duration_cast<std::chrono::seconds>(tstamp).count();
   int32_t nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(tstamp).count() % 1000000000UL;
   std::cout << "sec: " << sec << " nsec: " << nsec << " since epoch: \n";
   ros::Time n(sec, nsec);
   return 0;
}

Hi ros::Time are sec and nsec since epoch

 #include <iostream>
 #include <chrono>
 #include <ctime>
 #include <ros/ros.h>

int main()
{
    const auto p0 = std::chrono::time_point<std::chrono::high_resolution_clock>{};
    const auto p3 = std::chrono::high_resolution_clock::now();

   std::chrono::duration  auto tstamp = p3.time_since_epoch();
p3 - p0;
    int32_t sec = std::chrono::duration_cast<std::chrono::seconds>(tstamp).count();
    int32_t nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(tstamp).count() % 1000000000UL;
    std::cout << "sec: " << sec << " nsec: " << nsec << " since epoch: \n";
    ros::Time n(sec, nsec);
    return 0;
}