2016-05-20 5 views
-2

私は小額の電卓を持っており、毎月の徴収日をカレンダー(テーブル)に追加する必要はありません。例えばJavaScriptで毎月の信用度のカレンダーを生成する

、私は第1料金の日付に2016年11月10日と支払いを持っています。これを行うにはどのように

# | date | fee 1 | 10.11.2016 | 500$ 2 | 10.12.2016 | 500$ 3 | 10.01.2017 | 500$ 4 | 10.02.2017 | 500$ ... 12 | 10.10.2017 | 11$

:表はこのようにすべきですか?

答えて

0
Date.isLeapYear = function (year) { 
    return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0)); 
}; 

Date.getDaysInMonth = function (year, month) { 
    return [31, (Date.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]; 
}; 

Date.prototype.isLeapYear = function() { 
    return Date.isLeapYear(this.getFullYear()); 
}; 

Date.prototype.getDaysInMonth = function() { 
    return Date.getDaysInMonth(this.getFullYear(), this.getMonth()); 
}; 

Date.prototype.addMonths = function (value) { 
    var n = this.getDate(); 
    this.setDate(1); 
    this.setMonth(this.getMonth() + value); 
    this.setDate(Math.min(n, this.getDaysInMonth())); 
    return this; 
}; 
関連する問題