function today() { var date = new Date(); var day = date.getDay(); if(day == 0) { day = "日"; } var today = "现在是:" + (date.getFullYear()) + "年" + (date.getMonth() + 1) + "月" + date.getDate() + "日" + "星期" + day + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); document.getElementById("today").innerHTML = today; }
代码片段
<body onload="today();"> <font id="today"></font> <bady>