【JS】时间走动特效用封装函数在小于10的数的前面加0

来源:互联网 发布:sqlserver数据库维护 编辑:程序博客网 时间:2024/04/27 14:53
<!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>
</head>
<body onload="TimeRun();Ctime();">
<div id="div1" name="div1"  align="center" style="width:auto; height:500px; line-height:100px;">
</div>
</body>
<script language="javascript" type="text/javascript">
//时间走动
function TimeRun(){
var now=new Date();
var year=now.getFullYear();
var month=now.getMonth()+1;//月份少1
var date=now.getDate();
var week = "星期" + "日一二三四五六".split(/(?!\b)/)[now.getDay()];
var hours=now.getHours();
if(hours<10){
hours="0"+hours;
}
var minutes=now.getMinutes();
if(minutes<10){
minutes="0"+minutes;
}
var seconds=now.getSeconds();
if(seconds<10){
seconds="0"+seconds;
}
var nowTime=year+"年"+month+"月"+date+"日 "+week+"  "+hours+":"+minutes+":"+seconds;
var div1=document.getElementById("div1");
div1.innerHTML="<font style='font-size:66px; background-color:;font-family:collegiateHeavyOutline;font-weight:bold;'color='red';>"+nowTime+"</font>";
//setInterval("TimeRun()",1000);//不要放到函数中,否则就是个死循环
}
setInterval("TimeRun()",1000);//每1000毫秒调用一次函数
</script>
</html>
0 0
原创粉丝点击