随笔 - 59  文章 - 70  trackbacks - 0
<2008年8月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(5)

随笔分类

随笔档案

搜索

  •  

积分与排名

  • 积分 - 173006
  • 排名 - 338

最新评论

阅读排行榜

评论排行榜

之前写了获取本地时间的代码,后来发现很不仁道,如果别人的机器时间不对,页面上显示的时间也不对了,会给别人造成困扰。于是乎将代码改了一下,用xmlHttpRequest对象来取得服务器上的时间
<script language="JavaScript" type="text/JavaScript">
var myday = "";
var mymonth = "";
var myweekday = "";
var year = "";
var myyear = "";
var weekday = "";
var http_request = "";
if(window.XMLHttpRequest){
  try{http_request = new XMLHttpRequest();} catch (e){;}  
}else if(window.ActiveXObject){ 
  try{ http_request = new ActiveXObject("Msxml2.XMLHTTP");} catch (e){ ; }
  if( http_request == null){
    try { http_request = new ActiveXObject("Microsoft.XMLHTTP");}   catch (e){;}
  }
}
http_request.open('HEAD', '.', false);
http_request.send(null);
var mydate = new Date(http_request.getResponseHeader('Date'));
myweekday=mydate.getDay();
mymonth=mydate.getMonth()+1;
myday= mydate.getDate();
myyear= mydate.getFullYear();
if(myweekday == 0)
weekday=" 星期日 ";
else if(myweekday == 1)
weekday=" 星期一 ";
else if(myweekday == 2)
weekday=" 星期二 ";
else if(myweekday == 3)
weekday=" 星期三 ";
else if(myweekday == 4)
weekday=" 星期四 ";
else if(myweekday == 5)
weekday=" 星期五 ";
else if(myweekday == 6)
weekday=" 星期六 ";
document.write(year+"年"+mymonth+"月"+myday+"日 "+weekday);
</script> 

posted on 2008-08-11 11:38 JasonChou 阅读(214) 评论(0)  编辑  收藏 所属分类: html

只有注册用户登录后才能发表评论。


网站导航: