不多说自己上代码
这是我开始学javascript写的,现在发出来
<span id="clock" ></span>
function time() { var today = new Date(); var hou; var time; var day; if (today.getHours() < 12 && today.getHours() >= 0) { hou = today.getHours(); time = "AM"; } else if (today.getHours() <= 24 && today.getHours() > 12) { hou = today.getHours() - 12; time = "PM"; } var d = today.getDay(); if (d == 0) { day = "日"; } else if (d == 1) { day = "一"; } else if (d == 2) { day = "二"; } else if (d == 3) { day = "三"; } else if (d == 4) { day = "四"; } else if (d == 5) { day = "五"; } else if (d == 6) { day = "六"; } document.getElementById("clock").innerHTML = (today.getFullYear() + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日 " + hou + ":" + today.getMinutes() + ":" + today.getSeconds() + " " + time + " 星期" + day); } var myTime = setInterval("time()", 1000);
效果图
时间: 2024-10-27 18:33:28