zoukankan      html  css  js  c++  java
  • js中格式化时间

    //时间格式化
    Date.prototype.Format = function (fmt) { 
        var o = {
            "M+": this.getMonth() + 1, 
            "d+": this.getDate(), 
            "h+": this.getHours(), 
            "m+": this.getMinutes(),
            "s+": this.getSeconds(), 
            "q+": Math.floor((this.getMonth() + 3) / 3), 
            "S": this.getMilliseconds()
        };
        if (/(y+)/.test(fmt)){
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
                .substr(4 - RegExp.$1.length));
        }
        for (var k in o){
            if (new RegExp("(" + k + ")").test(fmt)){
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ?
                 (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            } 
        }
        return fmt;
    }
    

      调用方式:new Date( ).Format("yyyy-MM-dd");

  • 相关阅读:
    日报10.11
    日报10.9
    日报10.8
    日报10.7
    换马甲啦
    CSP2019知识点整理
    字符logo存档
    QHDYZ模拟赛20191027 提前透题
    数竞大佬jhc的三角函数复习题
    IO流
  • 原文地址:https://www.cnblogs.com/xiaohu1218/p/9629104.html
Copyright © 2011-2022 走看看