包含以下子模块: - VrCommon: 核心接口和数据结构 - VrUtils: 工具类库(JSON、log4cpp、tinyxml2、INI、MD5、CRC) - CloudUtils: 点云工具 - DataUtils: 数据处理工具(CloudMathClac、CoordinateTransform) - CloudView: 点云查看工具 功能说明: - 提供项目通用的基础工具类和实用功能 - 支持 Windows (MSVC/MinGW) 和 Linux (ARM/x86_64) 平台 - 使用 Qt qmake 构建系统 - 所有模块编译为静态库
73 lines
2.1 KiB
C++
73 lines
2.1 KiB
C++
#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);
|
|
}
|
|
|
|
/**
|
|
* 获取时间:年-月-日 时:分:秒
|
|
*/
|
|
std::string CVrDateUtils::GetStrNowTime(bool bYear)
|
|
{
|
|
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
|
|
char date[60] = { 0 };
|
|
#ifdef _WIN32
|
|
if (bYear)
|
|
{
|
|
sprintf_s(date, "%04d-%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_s(date, "%02d-%02d %02d:%02d:%02d", ptminfo.tm_mon + 1, ptminfo.tm_mday, ptminfo.tm_hour, ptminfo.tm_min, ptminfo.tm_sec);
|
|
}
|
|
#else
|
|
if (bYear)
|
|
{
|
|
sprintf(date, "%04d-%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", 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::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
|
}
|