获得本地时间的C语言代码

#include "time.h"
#include "stdio.h"
int main()
{
time_t seconds;
struct tm * timeinfo;
short hour,min,second,month,day;
int year;

time( &seconds );
timeinfo = localtime ( &seconds );

hour= timeinfo->tm_hour;
min= timeinfo->tm_min;
second=timeinfo->tm_sec;
year=timeinfo->tm_year+1900;
month=timeinfo->tm_mon+1;
day=timeinfo->tm_mday;
printf("%d-%d-%d %d:%d:%d/n",year,month,day,hour,min,second);
return 0;
}

你可能感兴趣的:(代码例子)