JS时间对像

new Date(); 当前系统的时间对象

var oBody=document.body;
 
fnTime();
setInterval(fnTime,1000);
 
function fnTime(){
  //myTime typeof object
  var myTime=new Date();
 
 
  //number
  var iYear=myTime.getFullYear();//年
  var iMonth=myTime.getMonth()+1;//月 正常的月必须加1+
  var iDate=myTime.getDate();//日
  var iWeek=myTime.getDay();//周
  var iHours=myTime.getHours();//小时
  var iMinutes=myTime.getMinutes();//分
  var iSeconds=myTime.getSeconds();//秒
 
  if(iWeek===0){
    iWeek="星期日";
  }else if(iWeek===1){
    iWeek="星期一";
  }else if(iWeek===2){
    iWeek="星期二";
  }else if(iWeek===3){
    iWeek="星期三";
  }else if(iWeek===4){
    iWeek="星期四";
  }else if(iWeek===5){
    iWeek="星期五";
  }else if(iWeek===6){
    iWeek="星期六";
  }
 
  var str="";
  str=iYear+"年"+iMonth+"月"+iDate+"日 "+"  "+iWeek+toTwo(iHours)+":"+toTwo(iMinutes)+":"+toTwo(iSeconds);
	oBody.innerHTML=str;
}
 
//小于10补零
function toTwo(n){
  if(n<10){
    return "0"+n;
  }else{
    return ""+n;
  }
}

  

  

  

posted @ 2017-11-21 13:48  carol72  阅读(141)  评论(0编辑  收藏  举报