您的位置:首页 > Web前端 > JavaScript

JS日期时间代码

2012-06-01 14:08 267 查看
<!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=gb2312" />

<title>JavaScript在线时钟,时间</title>

<script type="text/javascript">

function tim(){

var now=new Date;

this.year = now.getFullYear();

this.tmonth = now.getMonth() + 1;

this.tday = now.getDate();

this.week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[now.getDay()];

this.month = tmonth < 10 ? "0" + tmonth : tmonth;

this.day = tday < 10 ? "0" + tday : tday;

this.hour = now.getHours() < 10 ? "0" + now.getHours() : now.getHours();

this.minute = now.getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes();

this.second = now.getSeconds() < 10 ? "0" + now.getSeconds() : now.getSeconds();

document.getElementById("timespan").innerHTML="今天是"+year+"年"+month+"月"+day+"日,"+hour+":"+minute+":"+second+","+week;

var mm=setTimeout("tim()","1000");

}

</script>

</head>

<body onLoad="tim()">

<span id="timespan"></span>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: