2019年2月26日 星期二

javascript 日期相關函數應用

去掉時間
Date.prototype.date = function () {
   this.setHours(0, 0, 0, 0);
    return this;
}

月最後一天
Date.prototype.lastDay = function () {
    return new Date(this.getFullYear(), this.getMonth() + 1, 0);
}

月第一天
Date.prototype.firstDay = function () {
    return new Date(this.getFullYear(), this.getMonth(), 1);
}

增加月份
Date.prototype.addMonth = function (x) {
    this.setMonth(this.getMonth() + x);
    return this;
}

增加天數
Date.prototype.addDay = function (x) {
    this.setDate(this.getDate() + x);
    return this;
}

格式化為yyyymmdd
Date.prototype.yyyymmdd = function () {
    var mm = this.getMonth() + 1;
    var dd = this.getDate();
    return [this.getFullYear(),
    (mm > 9 ? '' : '0') + mm,
    (dd > 9 ? '' : '0') + dd
    ].join('');
};

沒有留言:

自訂權限驗證機制

// 使用 filter [Route("api/[controller]")] [ApiController] [Authorize] [TypeFilter(typeof(CustomAsyncAuthorizationFilter))] public c...