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

 

posted @ 2019-06-12 12:38  大芝麻  阅读(1725)  评论(0编辑  收藏  举报