日期:2014-05-16  浏览次数:20338 次

javaScript 显示当前日期
<!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>My Clock</title>
<script language="javascript" type="text/javascript">
function showtime() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
seconds = ((seconds < 10) ? "0"+seconds : seconds)
    myArray = new Array(6);
    myArray[0] = "星期日";
    myArray[1] = "星期一";
    myArray[2] = "星期二";
    myArray[3] = "星期三";
    myArray[4] = "星期四";
    myArray[5] = "星期五";
    myArray[6] = "星期六";
    weekday = now.getDay();
var clock = now.getFullYear() +"年"+(now.getMonth()+1)+"月"+now.getDate()+"日"+ hours+"时"+minutes+"分"+seconds+"秒"+myArray[weekday];
document.getElementById("theTime").innerHTML ="<font color='red'>"+clock+"</font>";
setTimeout("showtime()",1000);
}
</script>
</head>
<body  onload="showtime();">
<div id="theTime">
</div>
</body>
</html>