<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script>
window.onload = function(){
function nowTime(ev,type){
/*
* ev:显示时间的元素
* type:时间显示模式.若传入12则为12小时制,不传入则为24小时制
*/
//年月日时分秒
var Y,M,D,W,H,I,S
//月日时分秒为单位时前面补零
function fillZero(v){
if(v<10){v='0'+v}
return v
}
(function(){
var d=new Date()
Y=d.getFullYear()
M=fillZero(d.getMonth()+1)
D=fillZero(d.getDate())
H=fillZero(d.getHours())
I=fillZero(d.getMinutes())
S=fillZero(d.getSeconds())
ev.innerHTML=Y+'/'+M+'/'+D+'/ '+'&nbsp'+H+':'+I+':'+S
//每秒更新时间
setTimeout(arguments.callee,1000)
})()
}
nowTime(document.getElementById('time24'))
}
</script>
<body>
<div id="demo">
<h2 title="当前时间"><em>24小时制:</em><span id="time24"></span></h2>
</div>
</body>
</html>
直接使用即可.
本程序根本提问者要求(利用函数)所设计,并且调试成功!有什么不明白可以给我留言,请求加分!!
<html>
<head>
<title>显示当前日期及时间</title>
</head>
<body>
<script type="text/javascript">
/*本段函数控制小时、分钟、秒数的双位表示*/
function checkTime(i) {
if (i<10)
{i="0"+i}
return i
}
</script>
<script type="text/javascript">
var d = new Date() //新建一个Date对象
var year = d.getFullYear() //获取年份
var month = d.getMonth()+1 //获取月份
var day = d.getDate() //获取日期
var hour = d.getHours() //获取小时
var min = d.getMinutes() //获取分钟
var sec = d.getSeconds() //获取秒数
document.write(year+"-"+month+"-"+day+" "+checkTime(hour)+":"+checkTime(min)+":"+checkTime(sec))
</script>
</body>
</html>
<script language=JavaScript>var timerID = null
var timerRunning = false
function stopclock (){
if(timerRunning)
clearTimeout(timerID)
timerRunning = false}
function startclock () {
stopclock()
showtime()}
function showtime () {
var now = new Date()
var hours = now.getHours()
var minutes = now.getMinutes()
var seconds = now.getSeconds()
var timeValue = "" +((hours >= 12) ? "下午 " : "上午 " )
timeValue += ((hours >12) ? hours -12 :hours)
timeValue += ((minutes <10) ? ":0" : ":") + minutes
timeValue += ((seconds <10) ? ":0" : ":") + seconds
document.clock.thetime.value = timeValue
timerID = setTimeout("showtime()",1000)
timerRunning = true}
</SCRIPT>
<body onload=startclock()>
<form name=clock >
<input name=thetime style="font-size: 9ptcolor:#000000border:0" size=12>
</body>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)