用javascript写的倒计时,从某年某月距离到今天还有多少时间

 从现在距离2012年9月10日教师节的倒计时:

                    

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
<title>无标题文档</title>
<style>
div{
 
 display:inline;
 }
</style>
<script type="text/javascript">
var d = new Date();
//document.write(d.getTime()+"显示据当前的毫秒<br/>"  );
 

var old = Date.parse("Sep  10, 2012");
//document.write(old);
var a;   
a=(Date.parse("Sep 10, 2012")-d.getTime());
//alert(a);
function  jishi(){

yearTime=a/1000/60/60/24/30/12;
//alert(yearTime);
//间隔的年数
b=Math.floor(a/1000/60/60/24/30/12);
//取得那个整的数值
 
//document.write(b+"年");
 
monthTime=(yearTime-b)*12;
//计算还有多少个月

//alert(monthTime);
c=Math.floor(monthTime);
//document.write(c+"月");
//alert(c);
dayTime=(monthTime-c)*30;
//alert(dayTime);
//计算还有多少天
d=Math.floor(dayTime);
//document.write(d+"日");
//alert(d);
hourTime=(dayTime-d)*24;
//alert(hourTime);
h=Math.floor(hourTime);
//document.write(h+"小时");
//alert(h);
minuteTime=(hourTime-h)*60;
//alert(minuteTime);
m=Math.floor(minuteTime);
//alert(m);
//document.write(m+"分钟");
secondTime=(minuteTime-m)*60;
//alert(secondTime);

s=Math.floor(secondTime);
//document.write(s+"秒");
document.getElementById("monthdiv").innerHTML=c;
document.getElementById("daydiv").innerHTML=d;
document.getElementById("hourdiv").innerHTML=h;
document.getElementById("mdiv").innerHTML=m;
document.getElementById("sdiv").innerHTML=s;
setTimeout("jishi()",1000);
}

</script>
 
</head>

<body οnlοad="jishi()">
倒计时:据2012年9月10日还有
<div id="monthdiv" style="background-color:#3F9;width:10px;height:4px"></div>月
<div id="daydiv" style="background-color:#0F0;width:10px;height:4px"></div>天
<div id="hourdiv" style="background-color:#F00;width:5px;height:4px"></div>小时
<div id="mdiv" style="background-color:#6F9;width:5px;height:4px"></div>分钟
<div id="sdiv" style="background-color:#CF9;width:5px;height:4px"></div>秒

 

</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值