C函数获取系统时间按照格式打印赋值

#include <iostream>
#include <stdio.h>
#include <time.h>
using namespace std;


int main ()
{
time_t rawtime;
struct tm * timeinfo;


time(&rawtime);
timeinfo = localtime(&rawtime);
//printf("\007The current date/time is: %s", asctime(timeinfo));
char abc[20];
sprintf ( abc,"%4d-%02d-%02d %02d:%02d:%02d\n",1900+timeinfo->tm_year, 1+timeinfo->tm_mon,
timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec);
printf("%s",abc);
return 0;
}

你可能感兴趣的:(C函数获取系统时间按照格式打印赋值)