需求说明
制作显示年、月、日、星期几,并且显示上午(AM)和下午(PM)的十二进制的时钟
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>制作12进制的时钟特效</title> </head> <body onload="clock_12h()"> <h4 id="times"></h4> <script> function clock_12h() { var today = new Date(); var add = ""; if(today.getHours()<12){ add = "AM"; }else { add = "PM"; } document.getElementById("times").innerHTML=today.getFullYear()+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日"+"\t"+today.getHours()+":"+today.getMinutes()+":"+today.getSeconds()+"\t"+add+"\t"+"星期"+today.getDay(); } setInterval("clock_12h()",1000); </script> </body> </html>