js获取当前日期 时间

<!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>
现在时间:<span id="nows"></span>
<script>
sDate=new Date();
nYear=sDate.getFullYear();
nMonth=sDate.getMonth()+1;
nDate=sDate.getDate();
nHour=sDate.getHours();
nMinute=sDate.getMinutes();
nSecond=sDate.getSeconds();
nDay=sDate.getDay();

var weekDay=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");

var nows=document.getElementById("nows");
nows.innerText=nYear+"年"+nMonth+"月"+nDate+"日 "+nHour+":"+nMinute+":"+nSecond+" "+weekDay[nDay];
</script>

</body>
</html>

posted on 2011-02-09 13:27  woshilee  阅读(92)  评论(0)    收藏  举报

导航