TimeProgramme

JavaScript

Posted by Alexa on June 5, 2018

Just based on JavaScript to show localtime immediately

 <script>  
    function  show_time()  
    {  
        var today,hour,second,minute,year,month,date,time;  
            
        today=new Date();  
        
        year = today.getFullYear();  
        month = today.getMonth()+1;  
        date = today.getDate();  
        hour = today.getHours();  
        minute =today.getMinutes();  
        second = today.getSeconds();  
        if(minute < 10) minute = '0' + minute;  
       if(second < 10) second = '0' + second;  
       time = year + "-" + month + "-" + date +" " + hour + ":" + minute + ":" + second;  
       $("#nowdate").html(time);  
   }   
   setInterval(show_time,1000);  
 </script>