概述:
此文件描述了如何获取当前时间点并以动态的方式显示在Web浏览器端.
Web截图:
代码详情:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="卡布奇诺奶茶的独特">
<meta name="Keywords" content="时间钟">
<meta name="Description" content="此文件描述了如何简单获取当前时间点并以动态的方式显示在Web浏览器端.">
<title>获取当前时间钟</title>
</head>
<script type="text/javascript" language="javascript">
//获取当前时间钟
var count = 0;
function showTime(){
var d = new Date();
//年
var year = d.getFullYear();
if(year<10){
year = "0" + year;
}
//月
var month = d.getMonth() + 1;
if(month<10){
month = "0" + month;
}
//日
var day = d.getDate();
if(day<10){
day = "0" + day;
}
//时
var hour = d.getHours();
if(hour<10){
hour = "0" + hour;
}
//分
var minute = d.getMinutes();
if(minute<10){
minute = "0" + minute;
}
//秒
var second = d.getSeconds();
if(second<10){
second = "0" + second;
}
/*在此设置时间停止量
count ++;
if(count==3){
window.clearInterval(t);
}*/
document.getElementById("display").innerHTML = year+"年"+month+"月"+day+"日"+"\t"+hour+"时"+minute+"分"+second+"秒";
}
var t = window.setInterval("showTime()",1000);
</script>
<body>
<div id="display" style="background:#F2F2F2;font-weight:bold;"></div>
</body>
</html>
-----------------------------------------
感谢您的倾心阅读