From d615d9e045790ca7c3ac17212c470cd3249a50e0 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 11 Jun 2019 16:02:00 +0800 Subject: [PATCH] add TimestampToDatexxx --- a8/sysutils.cc | 30 ++++++++++++++++++++++++++++++ a8/sysutils.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/a8/sysutils.cc b/a8/sysutils.cc index 14e2243..9be7dbe 100644 --- a/a8/sysutils.cc +++ b/a8/sysutils.cc @@ -173,6 +173,36 @@ namespace a8 return std::string(buff); } + std::string TimestampToDateTime(time_t time_val) + { + std::string datetime_str; + { + time_t nowtime = time; + struct tm tm_time = {0}; + localtime_r(&nowtime, &tm_time); + + char buff[256]; + strftime(buff, a8::ArraySize(buff), "%F %T", &tm_time); + datetime_str.append((char*)buff); + } + return datetime_str; + } + + std::string TimestampToDate(time_t time_val) + { + std::string datetime_str; + { + time_t nowtime = time; + struct tm tm_time = {0}; + localtime_r(&nowtime, &tm_time); + + char buff[256]; + strftime(buff, a8::ArraySize(buff), "%F", &tm_time); + datetime_str.append((char*)buff); + } + return datetime_str; + } + time_t GetDaySeconds(time_t time_val, int incdays) { int g_time_zone = 8; diff --git a/a8/sysutils.h b/a8/sysutils.h index 72befc2..0ace7a6 100644 --- a/a8/sysutils.h +++ b/a8/sysutils.h @@ -77,6 +77,8 @@ namespace a8 std::string GetIpAddress(unsigned long ip_saddr); std::string FormatDateTime(time_t time_val); + std::string TimestampToDateTime(time_t time_val); + std::string TimestampToDate(time_t time_val); time_t GetDaySeconds(time_t time_val, int incdays = 0); time_t BetweenDays(time_t time_val1, time_t time_val2); time_t GetDateTimeSeconds(const char* datetime_str);