用JS實現實時顯示系統時間
阿新 • • 發佈:2017-10-27
class mon 星期 itl utf sso inner watermark cti
下面為大家附上代碼:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JS時間</title> <style> </style> </head> <body> <div id="time"></div> <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(); minutes = date.getMinutes(); seconds = date.getSeconds(); vWeek_s = date.getDay(); document.getElementById("time").innerHTML =year + "年" + month + "月" + day + "日" + "\t" + hours + ":" + minutes +":" + seconds + "\t" + vWeek[vWeek_s] ; }; setInterval("time()",1000); </script> </body> </html>
如果有錯誤或者有更好的方法實現效果,歡迎您來指導!!!
用JS實現實時顯示系統時間