利用 时间函数实现时间格式打印
#include <time.h>
#include <ctype.h>
time_t rawtime;
struct tm timeinfo;
TCHAR szTime[100];
time ( &rawtime );
localtime_s ( &timeinfo, &rawtime );
_tcsftime( szTime,ARRAYSIZE(szTime), _T("%a %Y-%m-%d %X"), &timeinfo);
利用传统字符串打印函数实现时间格式打印
#include <time.h>
#include <ctype.h>
time_t rawtime;
struct tm timeinfo;
TCHAR szTime[100];
time ( &rawtime );
localtime_s ( &timeinfo, &rawtime );
sprintf_s(szTime,ARRAYSIZE(szTime),
"%4d-%02d-%02d %02d:%02d:%02d",
1900+timeinfo.tm_year,
1+timeinfo.tm_mon,
timeinfo.tm_mday,
timeinfo.tm_hour,
timeinfo.tm_min,
timeinfo.tm_sec);