学习需要,在网上搜了不少,发现都是基于2的版本的,给大家贡献一个3的。
std::string DailyDuty::getSystemTime()
{
struct tm *tm;
struct timeval now;
gettimeofday(&now, NULL);
tm = localtime(&now.tv_sec);
int year = tm->tm_year + 1900;
int month = tm->tm_mon + 1;
int day = tm->tm_mday;
int hour=tm->tm_hour;
int min=tm->tm_min;
std::string string = StringUtils::format("%d-%d-%d %d:%d",year,month,day,hour,min);
return string;
}