html页面显示服务器时间

全局变量

var lblTimer;

var d;

ready事件里面写

lblTimer = $("#lbltimer");
d = new Date('<%=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")%>');
lblTimer.children("span").text(getStr(d))
setInterval("setTimer()", 1000);

 

function setTimer() {
var mss = d.getTime();
mss += 1000;
d.setTime(mss);
lblTimer.children("span").text(getStr(d))
}

function getStr(d) {
var YYYY = d.getFullYear(); //2011
var M = d.getMonth() + 1;
var MM = (M < 10) ? "0" + M : M;
var D = d.getDate();
var DD = (D < 10) ? "0" + D : D;
var h = d.getHours();
var hh = (h < 10) ? "0" + h : h;
var m = d.getMinutes();
var mm = (m < 10) ? "0" + m : m;
var s = d.getSeconds();
var ss = (s < 10) ? "0" + s : s;
var str = YYYY + "-" + MM + "-" + DD + " " + hh + ":" + mm + ":" + ss;
return str;
}

你可能感兴趣的:(html页面显示服务器时间)