mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
实现系统总览、统计分析的图标数据接口
This commit is contained in:
@@ -205,6 +205,23 @@ int64_t Utils::timeNowMS()
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
//return std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
|
||||
}
|
||||
int64_t Utils::timeNowDate()
|
||||
{
|
||||
// 获取当前时间
|
||||
auto now = std::chrono::system_clock::now();
|
||||
time_t t = std::chrono::system_clock::to_time_t(now);
|
||||
|
||||
// 转换为本地时间结构体
|
||||
struct tm* tmlocal = localtime(&t);
|
||||
|
||||
// 设置时分秒为0
|
||||
tmlocal->tm_hour = 0;
|
||||
tmlocal->tm_min = 0;
|
||||
tmlocal->tm_sec = 0;
|
||||
|
||||
// 转换回time_t
|
||||
return mktime(tmlocal);
|
||||
}
|
||||
string Utils::timeNowStr(std::string fmt /*= "%Y-%m-%dT%H:%M:%S"*/)
|
||||
{
|
||||
auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
|
||||
static int64_t timeNow();
|
||||
static int64_t timeNowMS();
|
||||
static int64_t timeNowDate();
|
||||
static string timeNowStr(std::string fmt = "%Y-%m-%d %H:%M:%S");
|
||||
static string timeNowStrMS(std::string fmt = "%Y-%m-%d %H:%M:%S");
|
||||
static string timeStr(int64_t ts, std::string fmt = "%Y-%m-%d %H:%M:%S");
|
||||
|
||||
Reference in New Issue
Block a user