// 服务器时间设置 var auto_server_time = { getLocalTime: function (i) { if (typeof i !== "number") { return new Date(); } var d = new Date(); var len = d.getTime(); var offset = d.getTimezoneOffset() * 60000; var utcTime = len + offset; return new Date(utcTime + 3600000 * i); }, dateTimeToString: function (date) { var y = date.getFullYear(); var M = date.getMonth() + 1; var d = date.getDate(); var H = date.getHours(); var m = date.getMinutes(); var s = date.getSeconds(); return y + '-' + (M < 10 ? ('0' + M) : M) + '-' + (d < 10 ? ('0' + d) : d) + " " + (H < 10 ? ('0' + H) : H) + ":" + (m < 10 ? ('0' + m) : m) + ":" + (s < 10 ? ('0' + s) : s); }, init: function () { let server_timezone = 8; // 时区 : 东区时区1~12 西区时区-1~-12 $("#showdate").html("服务器时间:" + this.dateTimeToString(this.getLocalTime(server_timezone))) }, myInterval: function (settime) { let t = null; return { start: function () { t = setTimeout(() => { auto_server_time.init(); this.start() }, settime); }, end: function () { clearTimeout(t); t = null; } } } } let auto_server_time_e1 = auto_server_time.myInterval(1000); auto_server_time_e1.start();