码迷,mamicode.com
首页 > Web开发 > 详细

js 时间

时间:2016-08-21 13:51:55      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
window.onload=function(){



setInterval(a





,1000);
a();

function a(){
var body=document.body;

var myTime = new Date();

var iYear = myTime.getFullYear();
var iMonth = myTime.getMonth()+1;
var iDate = myTime.getDate();
var iWeek = myTime.getDay();if(iWeek==0){

iWeek="星期天";if( iWeek === 0 ) iWeek = ‘星期日‘;
if( iWeek === 1 ) iWeek = ‘星期一‘;
if( iWeek === 2 ) iWeek = ‘星期二‘;
if( iWeek === 3 ) iWeek = ‘星期三‘;
if( iWeek === 4 ) iWeek = ‘星期四‘;
if( iWeek === 5 ) iWeek = ‘星期五‘;
if( iWeek === 6 ) iWeek = ‘星期六‘;



}
var iHours = myTime.getHours();
var iMin = myTime.getMinutes();
var iSec = myTime.getSeconds();
var str=iYear+ ‘年‘ +iMonth+‘月‘+iDate+‘日 ‘+ b(iWeek)+‘ ‘+ b(iHours)+‘ : ‘+ b(iMin)+‘ : ‘+ b(iSec);
body.innerHTML=str;

}
function b(n){

if(n<10){

return "0"+n;

}
else{
return ""+ n;
}



}

js 时间

标签:

原文地址:http://www.cnblogs.com/lidepeng/p/5792602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!