某人是1980年2月29日出生的,用js求距离他下一次生日的天数。
1个回答
展开全部
var cDate = new Date();
cDate.setFullYear( 1980 , 1 , 29 ) ;
cDate.setHours( 0 );
cDate.setMinutes( 0 );
cDate.setSeconds( 0 );
var cTime = cDate.getTime();
var nextYear = 1981 ;
var nextDate = new Date();
nextDate.setHours( 0 );
nextDate.setMinutes( 0 );
nextDate.setSeconds( 0 );
while( true ){
nextDate.setFullYear( nextYear , 1 , 29 );
if( 29 == nextDate.getDate() ){
break;
}
nextYear++ ;
}
var nextTime = nextDate.getTime();
alert( "天数:" + ( ( nextTime - cTime ) / ( 24*60*60*1000) ) );
cDate.setFullYear( 1980 , 1 , 29 ) ;
cDate.setHours( 0 );
cDate.setMinutes( 0 );
cDate.setSeconds( 0 );
var cTime = cDate.getTime();
var nextYear = 1981 ;
var nextDate = new Date();
nextDate.setHours( 0 );
nextDate.setMinutes( 0 );
nextDate.setSeconds( 0 );
while( true ){
nextDate.setFullYear( nextYear , 1 , 29 );
if( 29 == nextDate.getDate() ){
break;
}
nextYear++ ;
}
var nextTime = nextDate.getTime();
alert( "天数:" + ( ( nextTime - cTime ) / ( 24*60*60*1000) ) );
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询