js_window_date

Posted zxy01

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js_window_date相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
<meta charset="UTF-8">
<!--&lt;!&ndash; <script src="js_file01.js"></script>&ndash;&gt; 尽量放后body前边-->
<style>

#clock{
width: 250px;
}
</style>
</head>
<body>

<input type="text" id="clock">
<input type="button" value="begin" onclick="begin_click()">
<input type="button" value="end" onclick="end()">

<script>

function begin() {
var startTime=getTime();
var ret=document.getElementById("clock");
ret.value=startTime;
}

var ID;
function begin_click() {
// end();
if (ID==undefined){
begin();
ID=setInterval(begin,1000);
}
}

function end() {
clearInterval(ID);
ID=undefined;
}

function getWeek(n) {
week=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
return week[n];
}
// alert(week1(2));

function getTime() {
var date_obj=new Date();
var year=date_obj.getFullYear();
var month=date_obj.getMonth()+1;
var day=date_obj.getDate();
var hour=date_obj.getHours();
var minute=date_obj.getMinutes();
var seconds=date_obj.getSeconds();
var week=date_obj.getDay();

return year+"年"+month+"月"+day+"日"+" "+hour+"时"+minute+"分"+seconds+"秒"+" "+getWeek(week)
}
// alert(getTime());


</script>
</body>
</html>

以上是关于js_window_date的主要内容,如果未能解决你的问题,请参考以下文章