| | |
| | | #include <memory> |
| | | #include <sstream> |
| | | #include <algorithm> |
| | | |
| | | #include <ctime> |
| | | #include <iomanip> |
| | | #include <sstream> |
| | | |
| | | CToolUnits::CToolUnits() |
| | | { |
| | |
| | | std::snprintf(out, sizeof(out), "%s.%03d", date, ms); |
| | | return out; |
| | | } |
| | | |
| | | std::string CToolUnits::NowStrSec() |
| | | { |
| | | using namespace std::chrono; |
| | | auto now = system_clock::now(); |
| | | std::time_t t = system_clock::to_time_t(now); |
| | | std::tm tm{}; |
| | | #ifdef _WIN32 |
| | | localtime_s(&tm, &t); // 本地时间(Windows 线程安全) |
| | | #else |
| | | localtime_r(&t, &tm); // 本地时间(POSIX 线程安全) |
| | | #endif |
| | | std::ostringstream oss; |
| | | oss << std::put_time(&tm, "%Y%m%d%H%M%S"); // 例:2025-09-15 08:23:07 |
| | | return oss.str(); |
| | | } |