你可以剪掉你想要的部分-
alert(new Date().dayString('y','T'));
返回值:(字符串)2012 年 4 月 11 日上午 1:58
String.prototype.padZero= function(len, c){
var s= "", c= c || "0", len= (len || 2)- this.length;
while(s.length<len) s += c;
return s + this;
}
Date.daynames= ['Sunday', 'Monday', 'Tuesday',
'Wednesday','Thursday', 'Friday', 'Saturday'];
Date.ddmm= (function(){
return Date.parse('2/6/2009')>Date.parse('6/2/2009');
})();
Date.monthnames= ['January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October', 'November', 'December'];
Date.prototype.dayString= function(wch, wch2){
var D= this, A, day, M, W;
wch= wch? wch.toLowerCase():'y';
M= Date.monthnames;
W= Date.daynames;
var A= [W[D.getDay()], ' ', M[D.getMonth()], ' ',
D.getDate(), ', ', D.getFullYear()];
if(wch.indexOf('s')!= -1){
A[0]= A[0].substring(0, 3);
A[2]= A[2].substring(0, 3);
}
if(Date.ddmm || /b/i.test(wch)){
A.splice(2, 3, A[4], A[3], A[2]);
}
if(wch.indexOf('y')== -1) A.length= 5;
if(wch.indexOf('d')== -1) A.splice(0, 2);
day= A.join('');
if(wch2) day+= ' '+D.timeString(wch2);
return day;
}
Date.prototype.timeString= function(sec){
var D= this, A;
sec= sec || '';
var h= D.getHours();
var w= h<12? ' am':' pm';
if(sec===sec.toUpperCase())w=w.toUpperCase();
if(h>12) h-= 12;
else if(h== 0) h= 12;
A= [h, String(D.getMinutes()).padZero(2)];
if(/s/i.test(sec)) A[2]= String(D.getSeconds()).padZero(2);
if(/ms/i.test(sec)) A[3]= String(D.getMilliseconds()).padZero(3);
return A.join(':')+w;
}