code show as below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>时钟</title> <script> window.onload = function(){ showTime(); }; function showTime(){ var myDate = new Date(); var year = myDate.getFullYear(); varmonth The = myDate.getMonth () + . 1 ; var DATE = myDate.getDate (); var WEEKDAY = myDate.getDay (); var W = new new the Array ( . 6 ); W [ 0 ] = " Sunday " ; W [ . 1 ] = " Monday " ; W [ 2 ] = " Tuesday " ; W [ . 3] = " Wednesday " ; W [ . 4 ] = " Thursday " ; W [ . 5 ] = " Friday " ; W [ . 6 ] = " Saturday " ; var H = myDate.getHours (); var m = myDate.getMinutes () ; var S = myDate.getSeconds (); H = checktime (H); m = checkTime(m); s = checkTime(s); document.getElementById('time').innerHTML = year + '年' + month + '月' + date + '日' + w[weekday] + h + ':' + m + ':' + s; setTimeout(showTime,1000); } function checkTime(i){ if(i < 10){ return '0'+i; }else{ return i; } } </script> </head> <body> <div id="time"></div> </body> </html>
Results are as follows, has been walking time: