イベントフィルタ

701 ワード

パラメータを受け入れます.タイプはObjectオブジェクト(デフォルトは空のオブジェクト)このオブジェクトには2つのプロパティがあります.1つのタイムスタンプ(デフォルトは現在の時間)、1つの出力時間のフォーマット(デフォルトはyyyy-MM-dd hh:mm:ss)です.
function timeFilter(json){
    function toDou(n){
        return n<10?'0'+n:''+n;
    }
    var json = json || {};
    var timestamp = json.time || new Date().getTime();
    var oDate = new Date(timestamp);
    var model = json.model || 'yyyy-MM-dd hh:mm:ss';
    return model.replace(/y+/,oDate.getFullYear()).replace(/M+/,toDou(oDate.getMonth()+1)).replace(/d+/,toDou(oDate.getDate())).replace(/h+/,toDou(oDate.getHours())).replace(/m+/,toDou(oDate.getMinutes())).replace(/s+/,toDou(oDate.getSeconds()));
    }