EasyUI datetimebox 时间格式化

easyui 中惦记要对准时展开格式化,需要实现两独函数:formatter和parser。
其中:
formatter 函数使得选拔日期后用那格式化为我们用的格式。
parser 函数在选拔好日期后告诉控件咋样错过分析我们由定义之格式。

//控件定义
<input type="text" class="easyui-datetimebox" data-options="formatter:dateFormatter,parser:dateParser" >

/**
 * 时间格式化
 * @param value
 * @returns {string}
 */
function dateFormatter (value) {
    var date = new Date(value);
    var year = date.getFullYear().toString();
    var month = (date.getMonth() + 1);
    var day = date.getDate().toString();
    var hour = date.getHours().toString();
    var minutes = date.getMinutes().toString();
    var seconds = date.getSeconds().toString();
    if (month < 10) {
        month = "0" + month;
    }
    if (day < 10) {
        day = "0" + day;
    }
    if (hour < 10) {
        hour = "0" + hour;
    }
    if (minutes < 10) {
        minutes = "0" + minutes;
    }
    if (seconds < 10) {
        seconds = "0" + seconds;
    }
    return year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds;
}
/**
 * 解析时间
 */
function dateParser(s){
    var date = new Date(s);
    var year = date.getFullYear().toString();
    var month = (date.getMonth() + 1);
    var day = date.getDate().toString();
    var hour = date.getHours().toString();
    var minutes = date.getMinutes().toString();
    var seconds = date.getSeconds().toString();
    if (month < 10) {
        month = "0" + month;
    }
    if (day < 10) {
        day = "0" + day;
    }
    if (hour < 10) {
        hour = "0" + hour;
    }
    if (minutes < 10) {
        minutes = "0" + minutes;
    }
    if (seconds < 10) {
        seconds = "0" + seconds;
    }
    var str =  year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds;
    return str;
}

图片 1