时钟案例-Date(日期操作方法)

Original 2019-07-26 14:50:19 304
abstract:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>time案例</title> <style> .box{width:200px;height:200px;background-color:#ccc;flo
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>time案例</title>
<style>
.box{width:200px;height:200px;background-color:#ccc;float:left;border:1px solid #009688;border-radius:10px;line-height:200px;margin:10px auto;font-size:60px;text-align:center;}
.main{width:1200px;height:1200px;margin:200px auto;}
/*.sp{font-size:60px;color:#333333;line-height:200px;float:right;}*/
</style>
</head>
<body>
<div>
<div><h1 id="myday1"></h1></div>
<div id="box1"><p id="hours"></p></div>
<div id="box2"><p id="minutes"></p></div>
<div id="box3"><p id="seconds"></p></div>
</div>
<script type="text/javascript">
a=document.getElementById("myday1");
var myday=new Date();
// document.write("今天日期:"+myday.getFullYear()+"年");
var month=new Array(12);
month[0]="1月";
month[1]="2月";
month[2]="3月";
month[3]="4月";
month[4]="5月";
month[5]="6月";
month[6]="7月";
month[7]="8月";
month[8]="9月";
month[9]="10月";
month[10]="11月";
month[11]="12月";

var week=new Array(7);
week[1]="星期一";
week[2]="星期二";
week[3]="星期三";
week[4]="星期四";
week[5]="星期五";
week[6]="星期六";
week[0]="星期日";


a.innerHTML="今天日期:"+myday.getFullYear()+"年"+month[myday.getMonth()]+myday.getDate()+"号&nbsp;&nbsp;&nbsp;"+week[myday.getDay()];

b=document.getElementById("box1");
b.innerHTML=myday.getHours()+":";

c=document.getElementById("box2");
c.innerHTML=myday.getMinutes()+":";

e=document.getElementById("box3");
e.innerHTML=myday.getSeconds();

function  myrefresh() {
       window.location.reload();
} 
setTimeout( ' myrefresh() ' , 1000 );  // 指定1秒刷新一次 


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


Correcting teacher:查无此人Correction time:2019-07-27 11:20:48
Teacher's summary:完成的不错。js的日期时间,多用作选择日期时间。日期时间处理,一般都是php来做。继续加油

Release Notes

Popular Entries