js the date time conversion yyyy-mm-dd hh: MM: ss format string

js中date时间转换yyyyDate.prototype.format = function (format) {
           var args = {
               "M+": this.getMonth() + 1,
               "d+": this.getDate(),
               "h+": this.getHours(),
               "m+": this.getMinutes(),
               "s+": this.getSeconds(),
               "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
               "S": this.getMilliseconds()
           };
           if (/(y+)/.test(format))
               format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
           for (var i in args) {
               var n = args[i];
               if (new RegExp("(" + i + ")").test(format))
                   format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length));
           }
           return format;
       };
alert(newDATE ( 'the Sun On May 2018 09:08:09 GMT + 27 0800') the format ( "the MM-dd-YYYY HH: mm: SS." ));
 -Mm-dd HH: the MM: SS format string

It took a long time to do it, through the issue of deeply felt: Life is not easy, high front-end technology more difficult haha

Guess you like

Origin www.cnblogs.com/mahmud/p/11913043.html