js时间格式的转换

function System_dateInit(value) {
    if (value != null) {
        var d = new Date(value);
 
        var _d = System_date2str(d, "yyyy-MM-dd hh:mm:ss");
 
        return _d;
    } else {
        return "";
    }
 
}
 
function System_date2str(x, y) {
    var z = {
        y: x.getFullYear(),
        M: x.getMonth() + 1,
        d: x.getDate(),
        h: x.getHours(),
        m: x.getMinutes(),
        s: x.getSeconds()
    };
    return y.replace(/(y+|M+|d+|h+|m+|s+)/g, function (v) {
        return ((v.length > 1 ? "0" : "") + eval('z.' + v.slice(-1))).slice(-(v.length > 2 ? v.length : 2));
    });
}
posted @ 2016-05-06 15:41  华家宝贝冬冬  阅读(169)  评论(0编辑  收藏  举报