10 #include <pcl/pcl_exports.h>
25 getTimestamp(
const std::chrono::time_point<std::chrono::system_clock>& time =
26 std::chrono::system_clock::now())
29 std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch());
31 const auto s = std::chrono::duration_cast<std::chrono::seconds>(us);
32 std::time_t tt = s.count();
33 std::size_t fractional_seconds = us.count() % 1000000;
35 std::tm tm = *std::localtime(&tt);
37 ss << std::put_time(&tm,
"%Y%m%dT%H%M%S");
39 if (fractional_seconds > 0) {
40 ss <<
"." << std::setw(6) << std::setfill(
'0') << fractional_seconds;
51 PCL_EXPORTS inline std::chrono::time_point<std::chrono::system_clock>
54 std::istringstream ss;
58 std::size_t fractional_seconds = 0;
61 ss >> std::get_time(&tm,
"%Y%m%dT%H%M%S");
63 auto timepoint = std::chrono::system_clock::from_time_t(std::mktime(&tm));
65 const auto pos = timestamp.find(
'.');
67 if (pos != std::string::npos) {
68 const auto frac_text = timestamp.substr(pos+1);
70 ss >> fractional_seconds;
71 timepoint += std::chrono::microseconds(fractional_seconds);
PCL_EXPORTS std::chrono::time_point< std::chrono::system_clock > parseTimestamp(std::string timestamp)
Parses a iso timestring (see https://www.boost.org/doc/libs/1_81_0/doc/html/date_time/posix_time....
PCL_EXPORTS std::string getTimestamp(const std::chrono::time_point< std::chrono::system_clock > &time=std::chrono::system_clock::now())
Returns a timestamp in local time as string formatted like boosts to_iso_string see https://www....