无需使用库:
var startDate = "January 16, 2013";
var d = new Date(startDate);
var month = d.getMonth() + 1;
var day = d.getDate();
var year = d.getFullYear();
alert(month + "-" + day + "-" + year);
http://jsfiddle.net/mPBSf/
以下会将您的日期格式转换为有效的 ECMAScript 日期格式:
var startDate = "ApRiL 16, 2013";
var noCommas = startDate.replace(/\,/g,'');
var withDashes = noCommas.replace(/ /g,"-");
function monthsToNumbers(date)
{
var months = ["january","february","march","april","may","june","july","august","september","october","november","december"];
var year;
date = date.toLowerCase();
for(var i = 0; i < months.length; i++)
{
if(date.indexOf(months[i]) != -1)
{
if(i+1 < 10)
date = date.replace(months[i],"0" + (i+1));
else
date = date.replace(months[i],i+1);
}
}
year = date.match(/\d{4}/);
date = date.replace(year, "");
date = year + "-" + date;
date = date.substring(0,date.length-1);
return date;
}
var d = new Date(monthsToNumbers(withDashes));
var month = d.getMonth() + 1;
var day = d.getDate();
var year = d.getFullYear();
alert(d);
http://jsfiddle.net/kWzSv/1/