JS 自制页面小时钟


$(document).ready(function(e) { 
    function showTime(){        
      var myDate=new Date();

      var tYear=myDate.getFullYear();
      var tMonth=myDate.getMonth()+1;
      var tDay=myDate.getDate();
      var tHour=myDate.getHours();           
      var tMinute=myDate.getMinutes();           
      var tSecond=myDate.getSeconds();
      if(tMonth<10){
        tMonth = "0"+tMonth;
      }
      if(tDay<10){
        tDay = "0"+tDay;
      }
      if(tHour<10){
        tHour = "0"+tHour;
      } 
      if(tMinute<10){
        tMinute = "0"+tMinute;
      } 
      if(tSecond<10){
        tSecond = "0"+tSecond;
      }   
      var dateStr = tYear+"-"+tMonth+"-"+tDay+'<br/>'+tHour+":"+tMinute+":"+tSecond+"";  
      $("#date").html(dateStr);       
    }      
    showTime()
    var interval=window.setInterval(showTime, 1000); 
});

 

posted @ 2018-08-21 15:27  格鲁特baby  阅读(82)  评论(0编辑  收藏  举报