time_t转换成时间字符串
#include "stdafx.h" #include <fstream> #include <iostream> #include <string> #include <cstdlib> #include <time.h> using namespace std; int main() { time_t t; //秒时间 tm local; //本地时间 tm* gmt; //格林威治时间 char buf[128] = { 0 }; t = time(NULL); //获取目前秒时间 localtime_s(&local,&t); //转为本地时间 strftime(buf, 64, "%Y-%m-%d %H:%M:%S", &local); std::cout << buf << std::endl; return 0; }