C/C++ 《常用函数》
获取当前时间字符串
#include<iostream>
#include<time.h>
using namespace std;
std::string getLocalTimeString() {
time_t rawtime;
struct tm local_time;
time(&rawtime);
string retStr;
if (localtime_s(&local_time, &rawtime) == 0) {
retStr = to_string(1900 + local_time.tm_year) + '-' + to_string(1 + local_time.tm_mon) + '-' + to_string(local_time.tm_mday) + ' ' + to_string(local_time.tm_hour) + ':' + to_string(local_time.tm_min) + ':' + to_string(local_time.tm_sec);
}
return retStr;
}
本文来自博客园,作者:一个小笨蛋,转载请注明原文链接:https://www.cnblogs.com/paylove/p/18351048