HTM页面获得本机时间

function settimes() 
{
var time = new Date();
hours = time.getHours();
mins = time.getMinutes();
secs = time.getSeconds();
years = time.getFullYear();
mons = (time.getMonth() + 1);
days = time.getDate();

mons = (mons < 10 ? '0' : '') + mons;
days = (days < 10 ? '0' : '') + days;

hours = (hours < 10 ? '0' : '') + hours;
mins = (mins < 10 ? '0' : '') + mins;
secs = (secs < 10 ? '0' : '') + secs;

document.getElementById("ClientTime").value = years + "-" + mons + "-" + days + " " + hours + ":" + mins + ":" + secs;
getSysTime(); //显示系统时间
setTimeout('settimes()', 999); //刷新
}
</script>
<body onload="settimes()">
<input type="text" id="ClientTime" readonly name="ClientTime" size="20" />
</body>
原文地址:https://www.cnblogs.com/qingjoin/p/2271896.html