html页面的倒计时代码。。。。急求!!!!

html-css020

html页面的倒计时代码。。。。急求!!!!,第1张

<body>

<div id="timer"></div>

<script type="text/javascript" language="javascript">

var endDate=new Date(2010,11,11,17,05,40)//年月日时分秒,月要减去1

(function daoJiShi()

{

var now=new Date()

var oft=Math.round((endDate-now)/1000)

var ofd=parseInt(oft/3600/24)

var ofh=parseInt((oft%(3600*24))/3600)

var ofm=parseInt((oft%3600)/60)

var ofs=oft%60

document.getElementById('timer').innerHTML='还有 '+ofd+' 天 ' +ofh+ ' 小时 ' +ofm+ ' 分钟 ' +ofs+ ' 秒'

if(ofs<0){document.getElementById('timer').innerHTML='倒计时结束!'return}

setTimeout('daoJiShi()',1000)

}())

</script>

</body>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

</head>

<body>

<div id="box">

还剩:

<label for="" id="hour">00</label>小时

<label for="" id="minute">00</label>分

<label for="" id="second">00</label>秒

</div>

<script type="text/javascript">

var o_b=document.getElementById("box")

//获取界面标签对象

var o_h=document.getElementById("hour")

var o_m=document.getElementById("minute")

var o_s=document.getElementById("second")

function showTime(){

var nowDate=new Date()

//把结束时间转化为日期对象

console.log(nowDate)

var nowTime=nowDate.getTime()

var endDate=new Date("2019/01/20 00:00:00")

var endTime=endDate.getTime()

//距离结束时间剩余的秒数

var diffTime=parseInt((endTime-nowTime)/1000)

console.log(diffTime)

if(diffTime<=0){

o_b.innerHTML="秒杀结束"

clearInterval(t)//清除定时器

}

//将剩余时间(秒)转换为时、分、秒

var hour=parseInt(diffTime/60/60)

var minute=parseInt(diffTime/60%60)

var second=diffTime%60

if(hour<10){

hour="0"+hour

}

if(minute<10){

minute="0"+minute

}

if(second<10){

second="0"+second

}

console.log(o_h)

console.log(o_m)

console.log(o_s)

o_h.innerHTML=hour

o_m.innerHTML=minute

o_s.innerHTML=second

// setTimeout(showTime,1000)

}

showTime()

var t=setInterval(showTime,1000)

console.log(t)

</script>

</body>

</html>

<html>

<body>

<script>

var interval = 1000 

var year=2005

var month=4

var day=10

var divname="sj"

function ShowCountDown(year,month,day,divname) 

var now = new Date() 

var endDate = new Date(year, month-1, day) 

var leftTime=endDate.getTime()-now.getTime() 

var leftsecond = parseInt(leftTime/1000) 

//var day1=parseInt(leftsecond/(24*60*60*6)) 

var day1=Math.floor(leftsecond/(60*60*24)) 

var hour=Math.floor((leftsecond-day1*24*60*60)/3600) 

var minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60) 

var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60) 

var cc = document.getElementById(divname) 

cc.innerHTML = "距离"+year+"年"+month+"月"+day+"日还有:"+"<br>"+day1+"天"+hour+"小时"+minute+"分"+second+"秒" 

setInterval("ShowCountDown(year,month,day,divname)",100)

</script>

<div id="sj"></div>

</body>

</html>