<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>显示时间</title> </head> <body> <div id="time"></div> <script> function showTime() { var date = new Date(); // 年月日 var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); // 时分秒 var hour = date.getHours(); var minute = date.getMinutes(); var second = date.getSeconds(); // 实时显示 var element = document.getElementById('time'); element.innerHTML = '<h1>' + year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second; } setInterval('showTime()', 1000); </script> </body> </html>
原文出处:https://blog.csdn.net/HerryDong/article/details/103530019
标签:实时,month,date,second,year,var,js,转载 From: https://www.cnblogs.com/coding8832/p/17898896.html