zoukankan      html  css  js  c++  java
  • js时间对象格式化 format(转载)

    1. /** 
    2.  * 时间对象的格式化 
    3.  */  
    4. Date.prototype.format = function(format){  
    5.     /* 
    6.      * format="yyyy-MM-dd hh:mm:ss"; 
    7.      */  
    8.     var o = {  
    9.         "M+": this.getMonth() + 1,  
    10.         "d+": this.getDate(),  
    11.         "h+": this.getHours(),  
    12.         "m+": this.getMinutes(),  
    13.         "s+": this.getSeconds(),  
    14.         "q+": Math.floor((this.getMonth() + 3) / 3),  
    15.         "S": this.getMilliseconds()  
    16.     }  
    17.       
    18.     if (/(y+)/.test(format)) {  
    19.         format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 -  
    20.         RegExp.$1.length));  
    21.     }  
    22.       
    23.     for (var k in o) {  
    24.         if (new RegExp("(" + k + ")").test(format)) {  
    25.             format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));  
    26.         }  
    27.     }  
    28.     return format;  
    29. }  
  • 相关阅读:
    339. Nested List Weight Sum
    41. First Missing Positive
    366. Find Leaves of Binary Tree
    287. Find the Duplicate Number
    130. Surrounded Regions
    ubuntu18.04安装mongodb4.4
    阿里dataX配置使用
    MySQL主从同步简单介绍&配置
    阿里yugong配置使用
    ubuntu编译安装mysql
  • 原文地址:https://www.cnblogs.com/1wen/p/4246784.html
Copyright © 2011-2022 走看看