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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM