zoukankan      html  css  js  c++  java
  • 日期對象擴展,相加年,月,日[需要減時設置為負]

    /*************************************
    **    名稱:addMonths()                **
    **  功能:給日期加上指定月份            **
    **    參數: months    :相加月份數[int]    **
    **    返回: 相加後的日期                **
    ************************************
    */
    Date.prototype.addMonths
    =function(months){
        
    var year=parseInt(this.getFullYear());
        
    var month=parseInt(this.getMonth());//[0-11]
        //月份數大於12
        if(months>11){
            year
    =year+months/12;
            months=months%12;
        }
        
    if((month+months)>11){
            year
    =year+(month+months)/12;
            month=(month+months)%12;
        }
    else{
            month
    =month+months;
        }
        
    this.setFullYear(year);
        
    this.setMonth(month);
        
    return this;
    }
    /*************************************
    **    名稱:addDays()                   **
    **  功能:給日期加上指定天數            **
    **    參數: months    :相加天數[int]    **
    **    返回: 相加後的日期                **
    ************************************
    */
    Date.prototype.addDays
    =function(days){
        
    var day=parseInt(this.getDate());
        day
    +=days;
        
    this.setDate(day);
        
    return this;
    }
    /*************************************
    **    名稱:addYears()                   **
    **  功能:給日期加上指定年份            **
    **    參數: months    :相加年份數[int]    **
    **    返回: 相加後的日期                **
    ************************************
    */
    Date.prototype.addYears
    =function(years){
        
    var year=parseInt(this.getFullYear());
        year
    +=years;
        
    this.setFullYear(year);
        
    return this;
    }
  • 相关阅读:
    吉特仓储管系统(开源WMS)--分享两月如何做到10W+的项目
    吉特仓库管理系统(开源)-如何在网页端启动WinForm 程序
    RequireJS中的require如何返回模块
    RequireJS shim 用法说明
    从ISTIO熔断说起-轻舟网关熔断
    数据库与数据仓库的区别是什么
    API是什么
    要想业务中台建得快,最好用Service Mesh来带
    中台建设之路-中台建设怎么做?建设中台需要具备什么?
    为什么要建设中台
  • 原文地址:https://www.cnblogs.com/ywkpl/p/1383756.html
Copyright © 2011-2022 走看看