zoukankan      html  css  js  c++  java
  • js中date时间转换yyyy-mm-dd hh:MM:ss等格式字符串

    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等格式字符串

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

  • 相关阅读:
    LeetCode-434-字符串中的单词数
    LeetCode-415-字符串相加
    字符串
    序列
    元组
    列表
    repr()与str的区别
    输出函数print()
    输入函数input()
    MySQL中快速复制数据表方法汇总
  • 原文地址:https://www.cnblogs.com/mahmud/p/11913043.html
Copyright © 2011-2022 走看看