日期:2014-05-20  浏览次数:20366 次

如何把ASP.NET中显示的自动更新时间改成中文
做的网站中的母版页上有个自动更新,后来在浏览的时候发现是英文,求方法改成中文。
  <script type= "text/javascript">
  document.write(Date())
  </script>
显示是英文时间,如何才能让它显示成中文。

------解决方案--------------------
你可以给Date类加个方法,如下
JScript code
  Date.prototype.format = function(format){ 
var o = { 
"M+" : this.getMonth()+1, //month 
"d+" : this.getDate(), //day 
"h+" : this.getHours(), //hour 
"m+" : this.getMinutes(), //minute 
"s+" : this.getSeconds(), //second 
"q+" : Math.floor((this.getMonth()+3)/3), //quarter 
"S" : this.getMilliseconds() //millisecond 
} 

if(/(y+)/.test(format)) { 
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
} 

for(var k in o) { 
if(new RegExp("("+ k +")").test(format)) { 
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); 
} 
} 
return format; 
} 

//使用方法 
var now = new Date(); 
var nowStr = now.format("yyyy-MM-dd hh:mm:ss"); 
//使用方法2: 
var testDate = new Date(); 
var testStr = testDate.format("yyyy年MM月dd日hh小时mm分ss秒"); //输出:2011年11月20日09小时54分01秒
alert(testStr);