<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>页面上显示系统时间</title> </head> <body onload="showTime()"> 当前时间为:<span id="show"></span> </body> <script> function showTime() { var nowTime = new Date(); var years = nowTime.getFullYear(); var mouths = nowTime.getMonth(); var days = nowTime.getDate(); var hours = nowTime.getHours(); var minites = nowTime.getMinutes(); var seconds = nowTime.getSeconds(); var time = years+"年"; time += (mouths+1)+"月"+days+"日"; time += (hours<10?"0":"")+hours; time += (minites<10?":0":":") + minites; time += (seconds<10?":0":":") + seconds; time += (hours>12)?"PM":"AM"; document.getElementById("show").innerHTML = time; setTimeout("showTime()",1000); } </script> </html>