<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
安装如下步骤 *** 作:
1.在电脑磁盘空白出右键-新建,点击文档
2.将文档命名为index,用记事本打开
3.
写入一下代码,如图:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html"/>
<title>时间的动态显示</title>
</head>
<body>
</body>
</html>
4.在html头部写入获取时间的代码,如图
<script language="javascript">
var t = null
t = setTimeout(time,1000)//开始执行
function time()
{
clearTimeout(t)//清除定时器
dt = new Date()
var y=dt.getYear()+1900
var mm=dt.getMonth()+1
var d=dt.getDate()
var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]
var day=dt.getDay()
var h=dt.getHours()
var m=dt.getMinutes()
var s=dt.getSeconds()
if(h<10){h="0"+h}
if(m<10){m="0"+m}
if(s<10){s="0"+s}
document.getElementById("timeShow").innerHTML = "现在的时间为:"+y+"年"+mm+"月"+d+"日"+weekday[day]+"
"+h+":"+m+":"+s+""
t = setTimeout(time,1000)//设定定时器,循环执行
}
</script>
5.
在内容部分写入div标签,并附上ID,用来加载时间的载体。如图:
<div id="timeShow" class="time1"></div>
6.在头部写入div的样式如图,并保存
<style>
.time1{width:100%height:50pxbackground:#FFF000line-height:50pxtext-align:center}
</style>
7.保存后,将文件后缀命名为html。点击查看,勾选文件扩展名
8.文件后缀命名由txt改为html
9.使用浏览器打开文件
10.可以看到编写的文件,网页显示时间了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)