js获得当前系统时间
Posted 张张developer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js获得当前系统时间相关的知识,希望对你有一定的参考价值。
<script>
function get_time() {
var date = new Date();
var year = "", month = "", day = "", week = "", hour = "", minute = "", second = "";
year = date.getFullYear();
month = add_zero(date.getMonth() + 1);
day = add_zero(date.getDate());
hour = add_zero(date.getHours());
minute = add_zero(date.getMinutes());
second = add_zero(date.getSeconds());
document.getElementById("showSysDatetime").innerhtml = " " + year + "-"
+ month + "-" + day + " " + hour + ":" + minute + ":" + second;
}
function add_zero(temp) {
if (temp < 10)
return "0" + temp;
else
return temp;
}
setInterval("get_time()", 1000);
window.onload = get_time;
</script>
以上是关于js获得当前系统时间的主要内容,如果未能解决你的问题,请参考以下文章
js获得系统当前的时间getFullYear()和getYear()