美文网首页
事件过滤器

事件过滤器

作者: 小雞雞炖蘑菇 | 来源:发表于2017-03-17 08:37 被阅读0次

    接受一个参数,类型为Object对象(默认为空对象)
    此对象包含两个属性,一个时间戳(默认为当前时间),一个输出时间的格式(默认为"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()));
        }
    

    相关文章

      网友评论

          本文标题:事件过滤器

          本文链接:https://www.haomeiwen.com/subject/dunsnttx.html