前端js小玩意儿

<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
function ShowTime(){
var today=new Date();
var years=today.getFullYear();
var month=today.getMonth()+1;
var date=today.getDate();
var hours=today.getHours();
var minutes=today.getMinutes();
var seconds=today.getSeconds();
var day=today.getDay()+1;
var time="";

if(0<hours && hours<=12) {
document.getElementById("timer").innerHTML = years + " " + month + "-" + date + " " +
hours + ":" + minutes + ":" + seconds+" "+"AM"+" "+time;
}else if(hours>12 && hours<23) {
hours-=12;
document.getElementById("timer").innerHTML = years + " " + month + "-" + date + " " +
hours + ":" + minutes + ":" + seconds+" "+"PM"+" "+time;
}
}
setInterval(ShowTime,1000);

</script>
</head>
<body onload="ShowTime()">

<h1>当前时间为:<span id="timer"></span> </h1>
</body>

posted @ 2016-08-11 11:35  JokerJason  阅读(134)  评论(0编辑  收藏  举报

It's not who you are underneath, it's what you do that defines you

Brick walls are there for a reason :they let us prove how badly we want things