add TimestampToDatexxx

This commit is contained in:
aozhiwei 2019-06-11 16:02:00 +08:00
parent 6e5c873aec
commit d615d9e045
2 changed files with 32 additions and 0 deletions

View File

@ -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;

View File

@ -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);