utils.cpp 612 B

123456789101112131415161718192021
  1. #include "common/utils.hpp"
  2. #include <chrono>
  3. #include <iomanip>
  4. #include <sstream>
  5. #include "ByteTrack.h"
  6. #include "common/data.hpp"
  7. std::string getTimeString()
  8. {
  9. auto now = std::chrono::system_clock::now();
  10. auto t = std::chrono::system_clock::to_time_t(now);
  11. auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
  12. std::tm tm = *std::localtime(&t);
  13. std::ostringstream oss;
  14. oss << std::put_time(&tm, "%Y_%m_%d_%H_%M_%S")
  15. << "_" << std::setfill('0') << std::setw(3) << ms.count(); // 添加毫秒部分
  16. return oss.str();
  17. }