封装了个函数将Java时间转换为标准时间:
效果图:
js:
function todate(inputstr) {
var startTime = inputstr.split(",");
inputstr = inputstr + ""; //末尾加一个空格
var date = "";
var month = new Array();
month["Jan"] = "01";
month["Feb"] = "02";
month["Mar"] = "03";
month["Apr"] = "04";
month["May"] = "05";
month["Jun"] = "06";
month["Jul"] = "07";
month["Aug"] = "08";
month["Sep"] = "09";
month["Oct"] = "10";
month["Nov"] = "11";
month["Dec"] = "12";
var str1 = startTime[0].split(" ");
var str2 = startTime[1].split(" ");
var showsplit = "-";
var showsplit2 = " ";
var hourTime = str2[2].split(":");
var hour1 = hourTime[0];
var hour = "12";
var day = "";
if (parseInt(str1[1]) < 10) {
day = "0" + str1[1];
}
else {
day = str1[1];
}
date = str2[0];
if (str2[3] == "AM") {
if (hourTime[0] == "12") {
date += str2[1] + showsplit + month[str1[0]] + showsplit + day + showsplit2 + "00" + ":" + hourTime[1] + ":" + hourTime[2];
} else {
date += str2[1] + showsplit + month[str1[0]] + showsplit + day + showsplit2 + str2[2];
}
} else if (str2[3] == "PM") {
if (hourTime[0] == "12") {
date += str2[1] + showsplit + month[str1[0]] + showsplit + day + showsplit2 + str2[2];
} else {
date += str2[1] + showsplit + month[str1[0]] + showsplit + day + showsplit2 + (parseInt(hourTime[0]) + parseInt(hour)) + ":" + hourTime[1] + ":" + hourTime[2];
}
}
return date;
}