html页面动态显示时间,让时间走起来,JS自定义时间date格式
Date.prototype.format = function () {//给Date加上自定义属性:能格式化时间
var MM = this.getMonth() + 1;
if (this.getMonth() + 1 < 10) {
MM = "0" + MM;
}
var dd = this.getDate();
if (this.getDate() < 10) {
dd = "0" + dd;
}
var hh = this.getHours();
if (this.getHours() < 10) {
hh = "0" + hh;
}
var mm = this.getMinutes();
if (this.getMinutes() < 10) {
mm = "0" + mm;
}
var ss = this.getSeconds();
if (this.getSeconds() < 10) {
ss = "0" + ss;
}
return this.getFullYear() + "-" + MM + "-" + dd + " " + hh + ":" + mm + ":" + ss;
}
function moveDeviceDate() {
var datestr = $("#device_passdate").text();
if (!datestr || datestr.trim() == "") {
return;
}
var date = new Date(datestr);
datestr = new Date(date.getTime() + 1000).format();
$("#device_passdate").text(datestr);
}
setInterval(function () {
moveDeviceDate()
}, 1000);