#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; }