| | |
| | | |
| | | public: |
| | | // 获取当前时间戳 |
| | | static UINT16 getNowTimeStamp() { |
| | | static long getNowTimeStamp() { |
| | | auto now = std::chrono::system_clock::now(); |
| | | // 转换为时间戳 |
| | | auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now); |
| | | // 获取时间戳值 |
| | | auto value = now_ms.time_since_epoch().count(); |
| | | return value; |
| | | auto now_s = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count(); |
| | | |
| | | return now_s; |
| | | } |
| | | |
| | | static string format(long timestamp, string format="%Y-%m-%d %H:%M:%S") { |
| | | time_t rawtime = static_cast<time_t>(timestamp); |
| | | |
| | | // 使用localtime函数将time_t类型转换为struct tm结构体,获取本地时间 |
| | | struct tm* timeinfo; |
| | | timeinfo = localtime(&rawtime); |
| | | |
| | | char buffer[80]; |
| | | strftime(buffer, sizeof(buffer), format.c_str(), timeinfo); |
| | | // 将char数组转换为string |
| | | return std::string(buffer); |
| | | } |
| | | |
| | | |