#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\n", timebuf);
return 0;
}
结果:2015-06-12 03:44:54
原文地址:http://blog.csdn.net/liuguanghui1988/article/details/46474701