2025-06-08 12:48:04 +08:00
|
|
|
#include "VrDateUtils.h"
|
|
|
|
|
|
|
|
|
|
/**
|
2025-06-25 01:37:57 +08:00
|
|
|
* 获取时间年月日时分秒
|
2025-06-08 12:48:04 +08:00
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
}
|