GrabBag/VrUtils/Src/VrDateUtils.cpp

28 lines
923 B
C++
Raw Normal View History

2025-07-23 01:35:14 +08:00
#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);
}