jquery时时获取系统时间,补齐0
2017-05-10 11:06:54   来源:   浏览: 次

导读:unction current(){ var d=new Date(),str=& 39;& 39;; year=d getFullYear(); month=d getMonth()+1; if(month<10){ month=& 39
unction current(){
  var d=new Date(),str='';
  year=d.getFullYear();
  month=d.getMonth()+1;
  if(month<10){
    month='0'+month;
  }
  date=d.getDate();
  if(date<10){
    date='0'+date;
  }
  
  hours=d.getHours();
  if(hours<10){
    hours='0'+hours;
  }
  minutes=d.getMinutes();
  if(minutes<10){
    minutes='0'+minutes;
  }
  seconds=d.getSeconds();
  if(seconds<10){
    seconds='0'+seconds;
  }
  str=year+'-'+month+'-'+hours+' '+hours+':'+minutes+':'+seconds;
  return str;
}
$("#nowTime").text(current);
setInterval(function(){$("#nowTime").html(current)},1000);
 
<div id="nowTime"></div>
效果如下: