效果图:
页面:<div id="time"></div>
下面是js部分:
<script type="text/javascript"> function time() { var vWeek, vWeek_s, vDay; vWeek = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; var date = new Date(); year = date.getFullYear(); month = date.getMonth() + 1; day = date.getDate(); hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(); minutes = date.getMinutes()< 10 ? "0" + date.getMinutes() : date.getMinutes(); seconds = date.getSeconds()< 10 ? "0" + date.getSeconds() : date.getSeconds(); vWeek_s = date.getDay(); document.getElementById("time").innerHTML = " " + year + "年" + month + "月" + day + "日" + " " + hours + ":" + minutes + ":" + seconds + " " + vWeek[vWeek_s]; }; </script>