A-A+

JS动态显示年月日星期时分秒

2017年12月25日 网络技巧 暂无评论 阅读 1,309 次

<html>
<head>
<meta http-equiv="Content-Type” content="text/html; charset=gb2312">
<title>动态显示年月日星期时分秒</title>
<script type="text/javascript">
var days=new Array ("日", "一", "二", "三", "四", "五", "六");
function showDT() {
var currentDT = new Date();
var y,m,date,day,hs,ms,ss,theDateStr;
y = currentDT.getFullYear(); //四位整数表示的年份
m = currentDT.getMonth(); //月
date = currentDT.getDate(); //日
day = currentDT.getDay(); //星期
hs = currentDT.getHours(); //时
ms = currentDT.getMinutes(); //分
ss = currentDT.getSeconds(); //秒
theDateStr = y+"年"+ m +"月"+date+"日 星期"+days[day]+" "+hs+":"+ms+":"+ss;
document.getElementById("theClock"). innerHTML =theDateStr;
// setTimeout 在执行时,是在载入后延迟指定时间后,去执行一次表达式,仅执行一次
window.setTimeout( showDT, 1000);
}
</script>
</head>
<body onload="showDT()">
<div id="theClock" style="font-weight: bold; width: 300px;"></div>
</body>
</html>

标签:

给我留言