/*输入年月日时分秒,输出年月日时分秒的下一秒,输出仍然在原内存空间*/
void NextMinute(int *nYear,int *nMonth,int *nDate,int *nHour,int *nMinute,int *nSecond)
{
int nDays;
(*nSecond)++; /* 秒加1*/
if(*nSecond>=60) /*秒满60,做出特殊处理,下面时,日,月等类同 */
{
*nSecond=0;
(*nMinute)++;
if(*nMinute>=60)
{
*nMinute=0;
(*nHour)++;
if(*nHour>=24)
{
*nHour=0;
(*nDate)++;
switch(*nMonth)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
nDays=31;
break;
case 2:/* 判断闰年*/
if(*nYear%400==0||*nYear%100!=0&&*nYear%4==0)
{
nDays=29;
}
else
{
nDays=28;
}
break;
default:
nDays=30;
break;
}
if(*nDate>=nDays)
{
*nDate=1;
(*nMonth)++;
if(*nMonth>12)
{
*nMonth=1;
(*nYear)++;
}
}
}
}
}
}
/*示例可运行代码*/
void main()
{
int nYear=2004,nMonth=12,nDate=31,nHour=59,nMinute=59,nSecond=59;
NextMinute(&nYear,&nMonth,&nDate,&nHour,&nMinute,&nSecond);
printf("The result:%d-%d-%d %d:%d:%d",nYear,nMonth,nDate,nHour,nMinute,nSecond);
getch();
}