<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>在网页中插入时间 自动更新</title> </head> <body> <span id="sp_time"></span> <script type="text/javascript"> setInterval(function(){ var dd = new Date(); var y = dd.getFullYear(); var m = dd.getMonth() + 1; var d = dd.getDate(); var h = dd.getHours(); var mi = dd.getMinutes(); var s = dd.getSeconds(); var str = y + "年" + m + "月" + d + "日 " + h + ":" + mi + ":" + s + " 星期" + "日一二三四五六".charAt(dd.getDay()); document.getElementById("sp_time").innerHTML = str; },1000); </script> </body> </html> function show(){ var dd = new Date(); var y = dd.getFullYear(); var m = dd.getMonth() + 1; var d = dd.getDate(); var h = dd.getHours(); var mi = dd.getMinutes(); var s = dd.getSeconds(); var str = y + "年" + m + "月" + d + "日 " + h + ":" + mi + ":" + s + " 星期" + "日一二三四五六".charAt(dd.getDay()); document.getElementById("sp_time").innerHTML = str; } setInterval(show,1000); 时间:<span id="sp_time"></span>