• javascript时间函数


    //js格式化时间
    //"yyyy-MM-dd hh:mm:ss"
    Date.prototype.format = function (format) {
        var date = {
            "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+)/i.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        for (var k in date) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1
                                ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
            }
        }
        return format;
    }
    //时间加天数
    Date.prototype.addDays = function (day, format) {
        this.setDate(this.getDate() + day);
        return this.format(format);
    }
    //时间加周数
    Date.prototype.addWeeks = function (w) {
        this.addDays(w * 7);
    };
    //时间加月数
    Date.prototype.addMonths = function (m) {
        var d = this.getDate();
        this.setMonth(this.getMonth() + m);
    
        if (this.getDate() < d)
            this.setDate(0);
    };
    //时间加年数
    Date.prototype.addYears = function (y) {
        var m = this.getMonth();
        this.setFullYear(this.getFullYear() + y);
    
        if (m < this.getMonth()) {
            this.setDate(0);
        }
    };
    //根据日期,起得第几周
    Date.prototype.getWeek = function () {
        return new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[this.getDay()];
    }
    //获取参数,如:字符串('?a=hello&b=world'),window.location.search.parameter('a');
    String.prototype.parameter = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = this.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
    
  • 相关阅读:
    单实例GI数据库彻底清除
    crsctl & srvctl
    Err "CLSU-00104: additional error information: need ha priv"
    Err "Kernel panic
    安装JRE
    华为-RH5885 V3 远程KVM
    Swagger与OAuth 手动搭建WebApi 操作笔记
    xib自定义View
    iOS回收键盘
    iOS设置用户头像(从相册,图库或者拍照获取)
  • 原文地址:https://www.cnblogs.com/sntetwt/p/4208059.html
Copyright © 2020-2023  润新知