C++通过特定时间戳转日期

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33958297/article/details/78747309
把给定的时间戳转换成日期时间类型输入显示
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_NON_CONFORMING_SWPRINTFS
#include<stdio.h>
#include<time.h>
#include<tchar.h>
#include <memory.h>
int main()
{
      char *tszTmp = new char[50];
      memset(tszTmp, 0, 50);
      time_t time = 1512660328;//特定时间的时间戳    
      struct tm* pTimetm = localtime(&time);
      sprintf_s(tszTmp, 50 ,("%d-%02d-%02d %02d:%02d:%02d"), 1900 + pTimetm->tm_year, 1 + pTimetm->tm_mon, pTimetm->tm_mday, pTimetm->tm_hour, pTimetm->tm_min, pTimetm->tm_sec);
      printf("格式化后的时间:%s", tszTmp);
      delete[] tszTmp;
      return 0;
}

输出后的结果:


猜你喜欢

转载自blog.csdn.net/qq_33958297/article/details/78747309