回复 2楼 林月儿
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int i_sleep(int n)//延迟n秒函数
{
time_t start,end;
start=time(NULL);
end=time(NULL);
while(end-start<n)
{
end=time(NULL);
}
return 0;
}
int showtime()
{
struct tm timestru,*tmtime;
time_t endtime, curtime;
long ttime;
timestru.tm_year = 2020 - 1900;
timestru.tm_mon = 7 - 1;
timestru.tm_mday = 24;
timestru.tm_hour = 20;
timestru.tm_min = 0;
timestru.tm_sec = 0;
endtime = mktime(×tru);
curtime = time(NULL);
ttime = endtime - curtime;
tmtime = localtime(&curtime);
printf("当前时间 %04d年%02d月%02d日 %02d时%02d分%02d秒\n",
tmtime->tm_year + 1900, tmtime->tm_mon + 1, tmtime->tm_mday ,
tmtime->tm_hour, tmtime->tm_min, tmtime->tm_sec);
printf("距东京奥运 %04d年%02d月%02d日 %02d时%02d分%02d秒\n",
timestru.tm_year + 1900, timestru.tm_mon + 1, timestru.tm_mday,
timestru.tm_hour, timestru.tm_min, timestru.tm_sec);
printf("还有%3d天%02d时%02d分%02d秒\n",
ttime/86400, ttime%86400/3600, ttime%86400%3600/60, ttime%86400%3600%60);
return 0;
}
int main(int argc, char *argv[])
{
while(1)
{
system("cls");
showtime();
i_sleep(1);
}
return 0;
}
不好意思
这是复制别人的,然后改了一点