zoukankan      html  css  js  c++  java
  • time

    /**
     * 时间对象的格式化;
     
    */
     Date.prototype.format = function(format){
      /*
       * eg:format="YYYY-MM-dd hh:mm:ss";
       
    */
      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;
     }
  • 相关阅读:
    【File类:重命名功能】
    一段代码-Java
    Galahad
    简单的中位数
    小A的题 线段树区间赋值
    上升子序列方案数
    Superdoku 二分图匹配
    Haybale Guessing 区间并查集
    Dijkstra+二分查找
    莫比乌斯反演
  • 原文地址:https://www.cnblogs.com/sniper007/p/2218152.html
Copyright © 2011-2022 走看看