后台代码中将服务器时间显示出来
\n
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),”time”, “<script type=\\”text/javascript\\”>\\r\\n\\tvar strTime=\\”" + DateTime.Now.ToString(“yyyy-MM-dd HH:mm:ss”) + “\\”;\\r\\n</script>\\r\\n”);
前台使用javascript进行转换
\n
strTime=strTime.replace(/(-)/g,”/”);
var datNow=new Date(strTime);
var datLocalNow=new Date();
datC=datLocalNow-datNow;
function GetServerTime()
{
var datNow=new Date(new Date()-datC);
var strYear=datNow.getFullYear();
var strMonth=datNow.getMonth()+1;
strMonth=strMonth<10?”0″+strMonth:strMonth;
var strDay=datNow.getDate();
strDay=strDay<10?”0″+strDay:strDay;
var strHour=datNow.getHours();
strHour=strHour<10?”0″+strHour:strHour;
var strMinite=datNow.getMinutes();
strMinite=strMinite<10?”0″+strMinite:strMinite;
var strSecond=datNow.getSeconds();
strSecond=strSecond<10?”0″+strSecond:strSecond;
(“time”).innerHTML=strYear+”年”+strMonth+”月”+strDay+”日 “+strHour+”:”+strMinite+”:”+strSecond
}
GetServerTime();
setInterval(“GetServerTime()”,1000);
来源:http://www.cnblogs.com/liydotnet