怎么用asp程序写倒计时天数
我想写一个我们学校迎评倒计时的程序,既是写一个距2007年12月24号好有多少天!能不能跟详细一点?...
我想写一个我们学校迎评倒计时的程序,既是写一个距2007年12月24号好有多少天!
能不能跟详细一点? 展开
能不能跟详细一点? 展开
展开全部
我给你个用js写的.
是我的拙作。
<script>
var totaldays=0,totalhours=0,totalminutes=0,totalseconds=0;
var nextyear;
times=new Date(2007,12,24,0,0,0); //此处设置时间,格式是(年,月,日,时,分,秒),注意:设置的时间要超前当前时间,注意检查
now=new Date();
yy=now.getYear();
mm=now.getMonth();
dd=now.getDate();
hh=now.getHours();
minu=now.getMinutes();
ss=now.getSeconds();
tt=times.getYear()-yy;
timesTostring=times.getYear().toString()+(times.getMonth()<10?"0"+times.getMonth():times.getMonth()).toString()+
(times.getDate()<10?"0"+times.getDate():times.getDate()).toString()+(times.getHours()<10?"0"+times.getHours():times.getHours
()).toString()+(times.getMinutes()<10?"0"+times.getMinutes():times.getMinutes()).toString()+(times.getSeconds()
<10?"0"+times.getSeconds():times.getSeconds()).toString();
nowTostring=yy.toString()+((mm+1)<10? "0"+(mm+1):(mm+1)).toString()+(dd<10?"0"+dd:dd).toString()+(hh<10?"0"+hh:hh).toString
()+(minu<10?"0"+minu:minu).toString()+(ss<10?"0"+ss:ss).toString();
if(timesTostring<nowTostring)
alert("该网页包含一个倒计时程序\n程序内的日期已经过期\n请更新日期或者更新网页");
else{
if(tt>0){
for(i=1;i<tt;i++)
{nextyear=yy+i;
if(nextyear%4==0&&nextyear%100!=0)
totaldays+=366;
else
totaldays+=365;
}
for(i=0;i<(12-mm);i++)
{switch((mm+i)){
case 0: totaldays+=31;break;
case 1: totaldays+=28;break;
case 2: totaldays+=31;break;
case 3: totaldays+=30;break;
case 4: totaldays+=31;break;
case 5: totaldays+=30;break;
case 6: totaldays+=31;break;
case 7: totaldays+=31;break;
case 8: totaldays+=30;break;
case 9: totaldays+=31;break;
case 10: totaldays+=30;break;
case 11: totaldays+=31;break;
}
if(yy%4==0&&yy%100!=0)
{if(mm==1)
totaldays+=1;
}
}
totaldays-=dd;
for(i=0;i<times.getMonth()-1;i++)
{switch(i){
case 0: totaldays+=31;break;
case 1: totaldays+=28;break;
case 2: totaldays+=31;break;
case 3: totaldays+=30;break;
case 4: totaldays+=31;break;
case 5: totaldays+=30;break;
case 6: totaldays+=31;break;
case 7: totaldays+=31;break;
case 8: totaldays+=30;break;
case 9: totaldays+=31;break;
case 10: totaldays+=30;break;
case 11: totaldays+=31;break;
}
if(times.getYear()%4==0&×.getYear()%100!=0)
{if(i==1)
totaldays+=1;}
}
totaldays+=times.getDate()-1;
totalhours+=23-now.getHours()+times.getHours();
totalminutes+=60-now.getMinutes()+times.getMinutes()-1;
totalseconds+=60-now.getSeconds()+times.getSeconds();
if(totalseconds>59)
{totalseconds-=60;totalminutes+=1;}
if(totalminutes>59)
{totalminutes-=60;totalhours+=1;}
if(totalhours>23)
{totalhours-=24;totaldays+=1;}
}
else if(tt==0)
{pp=times.getMonth()-mm-1;
for(i=0;i<pp;i++)
{switch(mm+i){
case 0: totaldays+=31;break;
case 1: totaldays+=28;break;
case 2: totaldays+=31;break;
case 3: totaldays+=30;break;
case 4: totaldays+=31;break;
case 5: totaldays+=30;break;
case 6: totaldays+=31;break;
case 7: totaldays+=31;break;
case 8: totaldays+=30;break;
case 9: totaldays+=31;break;
case 10: totaldays+=30;break;
case 11: totaldays+=31;break;
}
if(times.getYear()%4==0&×.getYear()%100!=0)
{if(i==1)
totaldays+=1;}
}
totaldays+=times.getDate()-1-dd;
totalhours+=23-now.getHours()+times.getHours();
totalminutes+=60-now.getMinutes()+times.getMinutes()-1;
totalseconds+=60-now.getSeconds()+times.getSeconds();
if(totalseconds>59)
{totalseconds-=60;totalminutes+=1;}
if(totalminutes>59)
{totalminutes-=60;totalhours+=1;}
if(totalhours>23)
{totalhours-=24;totaldays+=1;}
}
/*显示时间函数*/
function showtime(){
if(totaldays==0&&totalhours==0&&totalminutes==0&&totalseconds==0)
{document.getElementById("showtime").innerHTML="距离迎评还有"+totaldays+"天"+(totalhours<10 ? "0"+totalhours:totalhours)+"小
时"+
(totalminutes<10? "0"+totalminutes:totalminutes)+"分"+(totalseconds<10? "0"+totalseconds:totalseconds)+"秒";
alert(times.getYear()+"-"+times.getMonth()+"-"+times.getDate()+" "+times.getHours()+":"+times.getMinutes()
+":"+times.getSeconds()+"\n倒计时时间到!");
}
else{
document.getElementById("showtime").innerHTML="距离迎评还有"+totaldays+"天"+(totalhours<10 ? "0"+totalhours:totalhours)+"小时
"+
(totalminutes<10? "0"+totalminutes:totalminutes)+"分"+(totalseconds<10? "0"+totalseconds:totalseconds)+"秒";
totalseconds--;
if(totalseconds==-1)
{totalminutes--;
totalseconds=59;
if(totalminutes==-1)
{totalhours--;
totalminutes=59; }
if(totalhours==-1)
{totaldays--;
totalhours=23;
}
}
setTimeout("showtime()",1000);
}}
window.onload=showtime;
}
</script>
<span id="showtime"></span>
是我的拙作。
<script>
var totaldays=0,totalhours=0,totalminutes=0,totalseconds=0;
var nextyear;
times=new Date(2007,12,24,0,0,0); //此处设置时间,格式是(年,月,日,时,分,秒),注意:设置的时间要超前当前时间,注意检查
now=new Date();
yy=now.getYear();
mm=now.getMonth();
dd=now.getDate();
hh=now.getHours();
minu=now.getMinutes();
ss=now.getSeconds();
tt=times.getYear()-yy;
timesTostring=times.getYear().toString()+(times.getMonth()<10?"0"+times.getMonth():times.getMonth()).toString()+
(times.getDate()<10?"0"+times.getDate():times.getDate()).toString()+(times.getHours()<10?"0"+times.getHours():times.getHours
()).toString()+(times.getMinutes()<10?"0"+times.getMinutes():times.getMinutes()).toString()+(times.getSeconds()
<10?"0"+times.getSeconds():times.getSeconds()).toString();
nowTostring=yy.toString()+((mm+1)<10? "0"+(mm+1):(mm+1)).toString()+(dd<10?"0"+dd:dd).toString()+(hh<10?"0"+hh:hh).toString
()+(minu<10?"0"+minu:minu).toString()+(ss<10?"0"+ss:ss).toString();
if(timesTostring<nowTostring)
alert("该网页包含一个倒计时程序\n程序内的日期已经过期\n请更新日期或者更新网页");
else{
if(tt>0){
for(i=1;i<tt;i++)
{nextyear=yy+i;
if(nextyear%4==0&&nextyear%100!=0)
totaldays+=366;
else
totaldays+=365;
}
for(i=0;i<(12-mm);i++)
{switch((mm+i)){
case 0: totaldays+=31;break;
case 1: totaldays+=28;break;
case 2: totaldays+=31;break;
case 3: totaldays+=30;break;
case 4: totaldays+=31;break;
case 5: totaldays+=30;break;
case 6: totaldays+=31;break;
case 7: totaldays+=31;break;
case 8: totaldays+=30;break;
case 9: totaldays+=31;break;
case 10: totaldays+=30;break;
case 11: totaldays+=31;break;
}
if(yy%4==0&&yy%100!=0)
{if(mm==1)
totaldays+=1;
}
}
totaldays-=dd;
for(i=0;i<times.getMonth()-1;i++)
{switch(i){
case 0: totaldays+=31;break;
case 1: totaldays+=28;break;
case 2: totaldays+=31;break;
case 3: totaldays+=30;break;
case 4: totaldays+=31;break;
case 5: totaldays+=30;break;
case 6: totaldays+=31;break;
case 7: totaldays+=31;break;
case 8: totaldays+=30;break;
case 9: totaldays+=31;break;
case 10: totaldays+=30;break;
case 11: totaldays+=31;break;
}
if(times.getYear()%4==0&×.getYear()%100!=0)
{if(i==1)
totaldays+=1;}
}
totaldays+=times.getDate()-1;
totalhours+=23-now.getHours()+times.getHours();
totalminutes+=60-now.getMinutes()+times.getMinutes()-1;
totalseconds+=60-now.getSeconds()+times.getSeconds();
if(totalseconds>59)
{totalseconds-=60;totalminutes+=1;}
if(totalminutes>59)
{totalminutes-=60;totalhours+=1;}
if(totalhours>23)
{totalhours-=24;totaldays+=1;}
}
else if(tt==0)
{pp=times.getMonth()-mm-1;
for(i=0;i<pp;i++)
{switch(mm+i){
case 0: totaldays+=31;break;
case 1: totaldays+=28;break;
case 2: totaldays+=31;break;
case 3: totaldays+=30;break;
case 4: totaldays+=31;break;
case 5: totaldays+=30;break;
case 6: totaldays+=31;break;
case 7: totaldays+=31;break;
case 8: totaldays+=30;break;
case 9: totaldays+=31;break;
case 10: totaldays+=30;break;
case 11: totaldays+=31;break;
}
if(times.getYear()%4==0&×.getYear()%100!=0)
{if(i==1)
totaldays+=1;}
}
totaldays+=times.getDate()-1-dd;
totalhours+=23-now.getHours()+times.getHours();
totalminutes+=60-now.getMinutes()+times.getMinutes()-1;
totalseconds+=60-now.getSeconds()+times.getSeconds();
if(totalseconds>59)
{totalseconds-=60;totalminutes+=1;}
if(totalminutes>59)
{totalminutes-=60;totalhours+=1;}
if(totalhours>23)
{totalhours-=24;totaldays+=1;}
}
/*显示时间函数*/
function showtime(){
if(totaldays==0&&totalhours==0&&totalminutes==0&&totalseconds==0)
{document.getElementById("showtime").innerHTML="距离迎评还有"+totaldays+"天"+(totalhours<10 ? "0"+totalhours:totalhours)+"小
时"+
(totalminutes<10? "0"+totalminutes:totalminutes)+"分"+(totalseconds<10? "0"+totalseconds:totalseconds)+"秒";
alert(times.getYear()+"-"+times.getMonth()+"-"+times.getDate()+" "+times.getHours()+":"+times.getMinutes()
+":"+times.getSeconds()+"\n倒计时时间到!");
}
else{
document.getElementById("showtime").innerHTML="距离迎评还有"+totaldays+"天"+(totalhours<10 ? "0"+totalhours:totalhours)+"小时
"+
(totalminutes<10? "0"+totalminutes:totalminutes)+"分"+(totalseconds<10? "0"+totalseconds:totalseconds)+"秒";
totalseconds--;
if(totalseconds==-1)
{totalminutes--;
totalseconds=59;
if(totalminutes==-1)
{totalhours--;
totalminutes=59; }
if(totalhours==-1)
{totaldays--;
totalhours=23;
}
}
setTimeout("showtime()",1000);
}}
window.onload=showtime;
}
</script>
<span id="showtime"></span>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询