c++获取系统当前时间并格式化,localtime_s函数比localtime函数更加安全
char str[80] = {0};
time_t cTime = time(nullptr);
struct tm tm_out;
localtime_s(&tm_out, &cTime);
sprintf(str, "%d-%d-%d %d-%d-%d",
1900 + tm_out.tm_year, tm_out.tm_mon + 1, tm_out.tm_mday,
tm_out.tm_hour, tm_out.tm_min, tm_out.tm_sec);
cout << str;