日期:2014-05-20 浏览次数:20747 次
function formatDate(date,pattern){
var s = pattern.split('-');
var result='';
for(var tmp in s){
switch(s[tmp]){
case 'y':
result += date.getFullYear() + '-';
break;
case 'm':
var month = date.getMonth()+1;
result += (month<10? '0'+month : month)+ '-';
break;
case 'd':
var day = date.getDate()+1;
result += (day<10? '0'+day : day);
result += date.getDate();
break;
}
}
if(result.lastIndexOf('-')==result.length-1){
retsult = result.substr(0,result.length-1);
}
return retsult;
}