我有小额信用计算器,我需要将月费日期添加到日历(表格)中。
例如,我有第一次收费日期10.11.2016和12付款。表应该是这样的:
# | 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$
这个怎么做?
我有小额信用计算器,我需要将月费日期添加到日历(表格)中。
例如,我有第一次收费日期10.11.2016和12付款。表应该是这样的:
# | 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$
这个怎么做?
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;
};