1. 程式人生 > >js獲得當前實時日期和時分秒星期

js獲得當前實時日期和時分秒星期

有一些東西,需要記下來,為以後使用,這是一個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=gb2312" />
<title>無標題文件</title>
<script language="javascript" type="text/javascript">
window.onload=function getNowTime(){   
    //取得當前時間   
    var now= new Date();   
    var year=now.getFullYear();   
    var month=now.getMonth()+1;   
    var day=now.getDate();   
    var hour=now.getHours();   
    var minute=now.getMinutes();   
    var second=now.getSeconds();   
	var week=now.getDay();
	var weekname="星期"+"天一二三四五六".split('')[week];
    var nowdate=year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second+" "+weekname;   
    document.getElementById("break_date").value = nowdate;   
    window.setTimeout("getNowTime()",1000);   
 }
</script>
</head>

<body>
<input type="text" id="break_date" size="30"/>
</body>
</html>