<script>
function show() {
var date = new Date();
var year = date.getFullYear();//年份
var month = date.getMonth() + 1;//月份
month =month<10? "0"+month:month
var day = date.getDay(); //周几
day = "日一二三四五六" .charAt(day)
day = "星期"+day;//星期几
var hour = date.getHours();//時
hour =hour<10? "0"+hour:hour;
var minute = date.getMinutes();//分
minute =minute<10? "0"+minute:minute;
var s = date.getSeconds();//秒
s =s<10? "0"+s:s;
var tian = date.getDate();
var result = year + "-" + month + "-" + tian + "-" + day + "-" + hour + "-" + minute + "-" + s;
document.getElementById("1").innerHTML = result;
}
show();
setInterval("show()", 1000)
</script>
显示结果如下:并且会实时更新