zoukankan      html  css  js  c++  java
  • javascript 追加date format属性。

    Date.prototype.format = function(format){
    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;
    };
    //how to use
    //var now = new Date();
    //var nowStr = now.format("yyyy-MM-dd hh:mm:ss");

  • 相关阅读:
    抽象工厂模式
    观察者模式
    建造者模式
    外观模式
    drf 之路由
    drf之视图
    drf--请求和响应
    def--序列化
    drf之restful规范
    Tepora使用
  • 原文地址:https://www.cnblogs.com/yangbt/p/3811955.html
Copyright © 2011-2022 走看看