From e62be6c99f145bdf2276dff0d90adf90427807c3 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 17 Nov 2018 16:37:33 +0800 Subject: [PATCH] add FormatDateTime --- a8/sysutils.cc | 10 ++++++++++ a8/sysutils.h | 1 + 2 files changed, 11 insertions(+) diff --git a/a8/sysutils.cc b/a8/sysutils.cc index 4076ac6..ef8603e 100644 --- a/a8/sysutils.cc +++ b/a8/sysutils.cc @@ -153,4 +153,14 @@ namespace a8 return std::string(buf); } + std::string FormatDateTime(time_t time_val) + { + struct tm tm_time = {0}; + localtime_r(&time_val, &tm_time); + + char buff[256]; + buff[0] = '\0'; + strftime(buff, a8::ArraySize(buff), "%F %T", &tm_time); + return std::string(buff); + } } diff --git a/a8/sysutils.h b/a8/sysutils.h index c4bcdc5..c910a13 100644 --- a/a8/sysutils.h +++ b/a8/sysutils.h @@ -63,6 +63,7 @@ namespace a8 bool MkDir(const std::string& path); void ForceCreateDir(const std::string& path); std::string GetIpAddress(unsigned long ip_saddr); + std::string FormatDateTime(time_t time_val); }