//jquery军用标准时间插件。 (function ($) { //默认参数 var defaluts = { url: "", backImg: '../img/time.png', width: 191, height: 59 }; var jybzsj = new Date().getTime(), tn = 0, vtimeInterval = null, timeInterval = null; $.fn.extend({ bdtimeInit: function (options) { var opts = $.extend({}, defaluts, options); //使用jQuery.extend 覆盖插件默认参数 var html = "
\n" + "
\n" + "

军用标准时间

\n" + "

\n" + "
\n" + "
"; $(this).html(html); $(".dbtimeContainer").css({ background: "url(" + opts.backImg + ") no-repeat", width: opts.width, height: opts.height }); initClock(opts.url); if (vtimeInterval) { clearInterval(vtimeInterval); } vtimeInterval = setInterval(function () { initClock(opts.url); }, 60000)//一分钟校验一次 } }); /** * 设置作战时间 */ function setClock() { if (timeInterval) { clearInterval(timeInterval) } timeInterval = setInterval(function () { newdata = new Date(jybzsj); newdata.setSeconds(newdata.getSeconds() + 1); jybzsj = newdata.getTime(); year = newdata.getFullYear(); month = (newdata.getMonth() + 1) < 10 ? '0' + (newdata.getMonth() + 1) : (newdata.getMonth() + 1); day = newdata.getDate() < 10 ? '0' + newdata.getDate() : newdata.getDate(); var hour = newdata.getHours() < 10 ? '0' + newdata.getHours() : newdata.getHours(); var mintes = newdata.getMinutes() < 10 ? '0' + newdata.getMinutes() : newdata.getMinutes(); var second = newdata.getSeconds() < 10 ? '0' + newdata.getSeconds() : newdata.getSeconds(); var hourF = hour.toString().substr(0, 1); var hourS = hour.toString().substr(1, 2); var mintesF = mintes.toString().substr(0, 1); var mintesS = mintes.toString().substr(1, 2); var secondF = second.toString().substr(0, 1); var secondS = second.toString().substr(1, 2); $(".standardTime .title .date").html(year + "-" + month + "-" + day); $(".standardTime .time").html(""); }, 1000); } /** * 初始化作战时间 */ function initClock(url) { $.ajax({ url: url, type: 'GET', timeout: 2000, dataType: 'json', success: function (data) { jybzsj = parseInt(data.data) * 1000; setClock() }, error: function () { jybzsj = new Date().getTime(); setClock(); } }) } })(jQuery);