java时间转换为标准时间

封装了个函数将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;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值