c++获取当前系统时间并格式化输出

#include 
#include 
using namespace std;

string getTime()
{
    time_t timep;
    time (&timep);
    char tmp[64];
    strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S",localtime(&timep) );
    return tmp;
}

int main(){
    string   time = getTime();
    cout << time << endl;

    return 0;
}

 

转载地址:https://www.cnblogs.com/danielStudy/p/6762107.html

你可能感兴趣的:(C/C++)