#include<sys/time.h>#include<stdio.h>#include<stdlib.h>#include<string.h>char*my_time(void){char*pstr=(char*)malloc(30);time_t t;
t =time(NULL);int year,month,day,hour,min,sec,week;structtm*p =localtime(&t);
year =1900+ p -> tm_year;//Year 需要加上1900
month = p -> tm_mon +1;//Month 需要加上1
day = p -> tm_mday;//Day
hour = p -> tm_hour;//Hour
min = p -> tm_min;//Minute
sec = p -> tm_sec;//Second
week = p -> tm_wday;//Week sprintf(pstr,"%d-%d-%d %d:%d:%d",year,month,day,hour,min,sec);return pstr;}intmain(void){char*pfile_name =my_time();printf("%s\n",pfile_name);return0;}