编程语言
首页 > 编程语言> > c++获取当前格式化时间

c++获取当前格式化时间

作者:互联网

#include <ctime>
std::string getNowTime() {
    time_t t = time(nullptr);
    struct tm *sTime = localtime(&t);
    char tmp[32]{0};
    snprintf(tmp, sizeof(tmp), "%04d-%02d-%02d %02d:%02d:%02d", 1900 + sTime->tm_year, 1 + sTime->tm_mon,
             sTime->tm_mday, sTime->tm_hour, sTime->tm_min, sTime->tm_sec);
    return tmp;
}

标签:tmp,02d,格式化,-%,c++,获取,tm,sTime,time
来源: https://www.cnblogs.com/icefoxhz/p/16523406.html