#include <sys/time.h>
#include <sys/types.h>
#include <linux/rtc.h>
#include <time.h>
char ss[200]
time_t timep;
struct tm *p;
time(&timep);
p=localtime(&timep); /*取得当地时间*/
sprintf(ss, "%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d", (1900+p->tm_year),(1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
printf("%s\n", ss);
输入结果:20120601015012