#include <time.h>
#include <stdio.h>
#include <string.h>
int main()
{
char timebuf[100]={0};
time_t timep;
struct tm *p_tm;
timep = time(NULL);
p_tm = localtime(&timep); /*获取本地时区时间*/
strftime(timebuf, sizeof(timebuf),"%Y-%m-%d %H:%M:%S",p_tm);
printf("%s
", timebuf);
return 0;
}
结果:2015-06-12 03:44:54