#include "VrDateUtils.h" /** * 获取时间年月日时分秒 */ std::string CVrDateUtils::GetNowTime() { time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); #ifdef _WIN32 struct tm ptminfo; localtime_s(&ptminfo, &tt); #else struct tm ptminfo = *(localtime(&tt)); #endif //printf("current: %02d-%02d-%02d %02d:%02d:%02d\n", // ptminfo.tm_year + 1900, ptminfo.tm_mon + 1, ptminfo.tm_mday, // ptminfo.tm_hour, ptminfo.tm_min, ptminfo.tm_sec); char date[60] = { 0 }; #ifdef _WIN32 sprintf_s(date, "%02d%02d%02d%02d%02d%02d", ptminfo.tm_year + 1900, \ ptminfo.tm_mon + 1, ptminfo.tm_mday, ptminfo.tm_hour, ptminfo.tm_min, ptminfo.tm_sec); #else sprintf(date, "%02d%02d%02d%02d%02d%02d", ptminfo.tm_year + 1900, \ ptminfo.tm_mon + 1, ptminfo.tm_mday, ptminfo.tm_hour, ptminfo.tm_min, ptminfo.tm_sec); #endif return std::string(date); } /** * 获取微妙时间戳 */ unsigned long long CVrDateUtils::GetTimestamp() { return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); }