第一种方法:
//对应的月份英文,设为全局变量
var dateParseMonth = {
"01":"JAN",
"02":"FED",
"03":"MAR",
"04":"APR",
"05":"MAY",
"06":"JUNE",
"07":"JULY",
"08":"AUG",
"09":"SEPT",
"10":"OCT",
"11":"NOV",
"12":"DEC"
}
var strDate = '2012-03-01';
var arr = strDate.split("-");
var rev = arr.reverse();//得到["01","03","2012"]
var mm = arr[1];//03
mm=dateParseMonth[mm];//此时mm就变成为MAR
var date = arr[0]+mm+arr[2];//得到01MAR2012
第二种方法:
//对应的月份英文,设为全局变量
var dateParseMonth = {
"1":"JAN",
"2":"FED",
"3":"MAR",
"4":"APR",
"5":"MAY",
"6":"JUNE",
"7":"JULY",
"8":"AUG",
"9":"SEPT",
"10":"OCT",
"11":"NOV",
"12":"DEC"
}
var strDate = '2012-03-01';
var val=Date.parse(strDate);//格式化成距1970年1月1日的毫秒数:1330560000000
var newDate=new Date(val);//newDate = Thu Mar 01 2012 08:00:00 GMT+0800(中国标准时间)
function toDDMMMYYYY(date) {
var dd = date.getDate() < 10 ? "0" + date.getDate() : date.getDate().toString();
var mm = date.getMonth()+1;//得到3
mm=dateParseMonth[mm]; //这里mm=MAR
var yyyy = d.getFullYear().toString();
var dateTime = dd + mm + yyyy;
console.log("dateTime:"+dateTime);//dateTime:01MAR2012
return dateTime;
}
个人喜欢第一种方式,代码比较少。