首页 > Web开发 > 详细

js中date时间转换yyyy-mm-dd hh:MM:ss等格式字符串

时间:2019-11-22 17:59:45      阅读:109      评论:0      收藏:0      [点我收藏+]
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(new Date( ‘Sun May 27 2018 09:08:09 GMT+0800‘).format("yyyy-MM-dd hh:mm:ss"));
-mm-dd hh:MM:ss等格式字符串

花了很长时间做出来的,通过这个问题深深的感受到:人生不易,高前端技术更不易 哈哈

js中date时间转换yyyy-mm-dd hh:MM:ss等格式字符串

原文:https://www.cnblogs.com/mahmud/p/11913043.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!