日期:2014-05-16 浏览次数:20393 次
//用来存放差值 var differentMillisec = 0; function init() { //取时间差值 getServerDate(); //取得显示时间 showtime(); } //取得显示时间 function showtime(){ now = new Date(); now.setTime(differentMillisec + now.getTime()); var str = now.getYear() + "年"; var temp = now.getMonth() + 1; if (temp < 10) str += "0"; str += temp + "月"; temp = now.getDate(); if (temp < 10) str += "0"; str += temp + "日"; var today = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"); str += " " + today[now.getDay()] + " "; temp = now.getHours(); if (temp < 10) str += "0"; str += temp + ":"; temp = now.getMinutes(); if (temp < 10) str += "0"; str += temp + ":"; temp = now.getSeconds(); if (temp < 10) str += "0"; str += temp; document.getElementById("Head1Right_Time").innerHTML = str; ctroltime=setTimeout("showtime()", 1000); } //从服务器取时间,用的buffalo取 function getServerDate() { begin = new Date(); millisecbeg = begin.getTime(); try { var buffalo = new Buffalo(endPointTop); buffalo.remoteCall("desktopService.getServerDate", [], function(reply) { var serverMillisec = reply.getResult(); end = new Date(); millisecend = end.getTime(); differentMillisec = serverMillisec - new Date() + (millisecend - millisecbeg)/2; }); } catch (ex) { } }
//获得服务器当前时间 public String getServerDate() { return String.valueOf(System.currentTimeMillis()); }