js中时间格式的处理方法

//格式化时间

function FormatDate(strTime) {

var date = new Date(strTime);
return (date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1) + "-" + (date.getDate() >= 10 ? date.getDate() : ("0" + date.getDate()));
}

 

 

//

  Date.prototype.format = function (format) {
            var o = {
                "M+": this.getMonth() + 1, // month
                "d+": this.getDate(), // day
                "h+": this.getHours(), // hour
                "m+": this.getMinutes(), // minute
                "s+": this.getSeconds(), // second
                "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
                "S": this.getMilliseconds()
                // millisecond
            }
            if (/(y+)/.test(format))
                format = format.replace(RegExp.$1, (this.getFullYear() + "")
                    .substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(format))
                    format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            return format;
        }


        function formatDatebox(value) {
            if (value == null || value == '') {
                return '';
            }

            var dt;
            d = new Date(value.replace("T", ""));
            dt = d;

            return dt.format("yyyy-MM-dd hh:mm:ss"); //扩展的Date的format方法(上述插件实现)
        }

 

    function FormatDate(strTime) {

            var date =new Date(strTime.replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '').replace(/-/g, "/"));
            return (date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1) + "-" + (date.getDate() >= 10 ? date.getDate() : ("0" + date.getDate()));
        }

 

posted @ 2016-11-23 14:13  Myisqq  阅读(35)  评论(0)    收藏  举报