#includeint year = 0;
int month = 0;
int day = 0;
int hour = 0;
int minute = 0;
int second = 0;
int main()
{
void inputdate(); /*输入年-月-日 时:分:秒*/
void nextsceond(); /*计算下一秒的时间*/
int leapyear(int year); /*判断是否为闰年*/
int daymonth(int month); /*返回每个月份对应的天数*/
inputdate();
leapyear(year);
daymonth(month);
nextsceond();
system("pause");
return 0;
}
/*函数inputdate()输入年-月-日 时:分:秒*/
void inputdate()
{
int loop;
for(loop = 0; loop < 3; loop++)
{
printf("请输入年-月-日 时:分:秒:");
scanf("%d-%d-%d %d:%d:%d", &year, &month, &day, &hour, &minute, &second);
if(month < 1 || month > 12)
{
printf("\t月份输入错误!\n");
continue;
}
else if(day < 1 || day > daymonth(month))
{
printf("\t日期输入错误!\n");
continue;
}
else if(hour < 0 || hour > 23)
{
printf("\t小时输入错误!\n");
continue;
}
else if(minute < 0 || minute > 59)
{
printf("\t分钟输入错误!\n");
continue;
}
else if(second < 0 || second > 59)
{
printf("\t秒数输入错误!\n");
continue;
}
else
{
break;
}
}
}
/*函数nextsecond()计算下一秒的时间*/
void nextsceond()
{
if(59 == second)
{
minute += 1;
second = 0;
if(60 == minute)
{
hour += 1;
minute = 0;
if(24 == hour)
{
day += 1;
hour = 0;
if(day > daymonth(month))
{
month += 1;
day = 1;
if(13 == month)
{
year += 1;
month = 1;
}
}
}
}
}
else
{
second += 1;
}
printf("%d-%d-%d %d:%d:%d\n",year, month, day, hour, minute, second);
}
/*函数leapyear(int year)判断是否为闰年*/
int leapyear(int year)
{
if(0 == (year % 4 && 0 != year % 100) || 0 == year % 400)
{
return 1;
}
else
{
return 0;
}
}
/*函数名daymonth(int month)返回每个月份对应的天数*/
int daymonth(int month)
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 2:
if(0 == (year % 4 && 0 != year % 100) || 0 == year %400)
{
return 29;
}
else
{
return 28;
}
case 4:
case 6:
case 9:
case 11:
return 30;
}
}
请放心使用
有问题的话请追问
满意请及时采纳,谢谢