//盗墓贼是个丑奴隶,原文
#包括
#包括
#包括
#包括
结构 tm * thisTime=NULL;
结构 tm World_Cup={0};
//返回当前时间,返回结构
结构 tm * getTime(){
time_t tloc=时间(&tloc);
thisTime=本地时间(&tloc);
thisTime->tm_year=1900+thisTime->tm_year;
thisTime->tm_mon=1+thisTime->tm_mon;
返回这个时间;
}
//设置世界杯时间的方法,返回结构体
结构 tm * setWorld_Cup(int y,int m,int d,int h){
World_Cup=(struct tm){.tm_year=y,.tm_mon=m,.tm_mday=d,.tm_hour=h};
返回 &World_Cup;
}
诠释主要(无效){
//世界杯:2019 年 8 月 31 日
结构 tm * 时间=getTime();
结构 tm * World_Cup=setWorld_Cup(2020,6,31,23);
int 年,星期一,日,小时距离世界杯倒计时距离世界杯倒计时,分钟,秒;
year=World_Cup->tm_year-time->tm_year;
如果(年> 0){
如果(时间->tm_mon-World_Cup->tm_mon==0){
如果(世界杯->tm_mday>时间->tm_mday){
printf("距离世界杯还有 %d 年 %d 天\n",year,World_Cup->tm_mday-time->tm_mday);
}别的{
printf("世界杯将在 %d 年后的本月举行\n",year);
}
}别的{
如果(世界杯->tm_mon>时间->tm_mon){
printf("a: 距离世界杯还有 %d 年 %d 个月\n",year,World_Cup->tm_mon-time->tm_mon);
}别的{
printf("b: 距离世界杯还有 %d 年 %d 个月\n",year-1,(12-time->tm_mon)+World_Cup->tm_mon);
}
}
}别的{
printf("日期参数错误\n");
返回-1;
}
返回0;
}
当前时间:2017/7/3
设置世界杯时间:
打印结果:
设置世界杯时间:
打印结果:
设置世界杯时间:
打印结果:
更多测试 ...................
获取当前时间,手动设置世界杯时间,然后减去。如果参数正确,则获得世界杯时间。如果参数错误,世界杯时间设置有问题。关于距离世界杯还有多少天和多少小时,再判断一次巢2。进行相应的打印