int date()
{
int year,mon,day,hour,min,sec,a
struct tm *d
time_t t
time(&t)
d=localtime(&t)
year=d->tm_year+1900
mon=d->tm_mon+1
day=d->tm_mday
hour=d->tm_hour
min=d->tm_min
sec=d->tm_sec
a=day+100*mon+10000*year
return a
}
void main()
{
struct tm *d
time_t t
//long t
time(&t)
//struct tm * local_time = localtime(&t)
d=localtime(&t)
printf("%s\n",ctime(&t))
printf("%d\n",d->tm_mon+1)
printf("%d\n",d->tm_mday)
printf("%d\n",d->tm_year+1900)
printf("%d\n",d->tm_hour)
printf("%d\n",date())
}
#include <time.h>time_t now
now = time (NULL)
printf("%s ",ctime(&now))
struct tm *tm time_t tchar timebuf[20]
memset(timebuf,0,sizeof(timebuf))
time(&t)
tm = localtime(&t)
strftime(timebuf,15,"%Y%m%d%H%M%S",tm)
printf("current time is [%s]",timebuf)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)