我需要将动态生成的日期从 2013 年 4 月 20 日转换为 20.04.13。到目前为止,我设法转换了月份并更换了垫片。但是转换年份仍然使我无法理解。这是我到目前为止想出的。如何前进?
$(document).ready(function() {
$('.date').each( function() {
var oldDate = $(this).text();
var month;
if( oldDate.indexOf('-') > 0 ){
var dateSplit = oldDate.split('-');
var year = dateSplit[2];
if( year.length == 2){
year = year;
}
switch(dateSplit[1])
{
case 'Jan': month = "01";
break;
case 'Feb': month = "02";
break;
case 'Mar': month = "03";
break;
case 'Apr': month = "04";
break;
case 'May': month = "05";
break;
case 'Jun': month = "06";
break;
case 'Jul': month = "07";
break;
case 'Aug': month = "08";
break;
case 'Sep': month = "09";
break;
case 'Oct': month = "10";
break;
case 'Nov': month = "11";
break;
case 'Dec': month = "12";
break;
}
$(this).text(dateSplit[0] + '.' + month + '.' + year);
}
else if( oldDate.indexOf(('/') > 0 ) ){
var dateSplit = oldDate.split('/');
var year = dateSplit[2];
if( year.length == 2){
year = year;
}
}
});
});