HTML的动态时间如何做…

html-css025

HTML的动态时间如何做…,第1张

<title>时间</title>

<script language="javascript">

//setTimeout("self.location.reload()",1000)

window.setInterval('showTime()',1000)

function showTime()

{

var enabled = 0

today = new Date()

var day

var date

if(today.getDay()==0) day = "星期日"

if(today.getDay()==1) day = "星期一"

if(today.getDay()==2) day = "星期二"

if(today.getDay()==3) day = "星期三"

if(today.getDay()==4) day = "星期四"

if(today.getDay()==5) day = "星期五"

if(today.getDay()==6) day = "星期六"

date = (today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日 " +

day+today.getHours()+":"+today.getMinutes()+":"+today.getSeconds()

document.getElementById("time").innerHTML=date

}

</script>

<body onload="showTime()">

<div id="time"></div>

</body>

</html>

把上边的代码保存成html网页,然后打开就可以了!

<title>时间</title>

<script language="javascript">

//setTimeout("self.location.reload()",1000)

window.setInterval('showTime()',1000)

function showTime()

{

var enabled = 0 

today = new Date()

var day 

var date

if(today.getDay()==0) day = "星期日"

if(today.getDay()==1) day = "星期一"

if(today.getDay()==2) day = "星期二"

if(today.getDay()==3) day = "星期三"

if(today.getDay()==4) day = "星期四"

if(today.getDay()==5) day = "星期五"

if(today.getDay()==6) day = "星期六"

date = (today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日 " + 

day+today.getHours()+":"+today.getMinutes()+":"+today.getSeconds()

document.getElementById("time").innerHTML=date

}

</script>

<body onload="showTime()">

<div id="time"></div>

</body>

</html>

把上边的代码保存成html网页,然后打开就可以了!

动的要用到JS。。下面的JS就可以做到: function tick() {

var hours, minutes, seconds, xfile

var intHours, intMinutes, intSeconds

var today, theday

today = new Date()

function initArray(){

this.length=initArray.arguments.length

for(var i=0i<this.lengthi++)

this[i+1]=initArray.arguments[i] }

var d=new initArray(

" 星期日",

" 星期一",

" 星期二",

" 星期三",

" 星期四",

" 星期五",

" 星期六")

theday = today.getYear()+"年" + [today.getMonth()+1]+"月" +today.getDate()+"日" + d[today.getDay()+1]

intHours = today.getHours()

intMinutes = today.getMinutes()

intSeconds = today.getSeconds()

if (intHours == 0) {

hours = "12:"

xfile = " 午夜 "

} else if (intHours <12) {

hours = intHours+":"

xfile = " 上午 "

} else if (intHours == 12) {

hours = "12:"

xfile = " 正午 "

} else {

intHours = intHours - 12

hours = intHours + ":"

xfile = " 下午 "

}

if (intMinutes <10) {

minutes = "0"+intMinutes+":"

} else {

minutes = intMinutes+":"

}

if (intSeconds <10) {

seconds = "0"+intSeconds+" "

} else {

seconds = intSeconds+" "

}

timeString = "现在是:"+theday+xfile+hours+minutes+seconds

document.getElementById("Clock").innerHTML = timeString

window.setTimeout("tick()", 100)

}

window.onload = tick