【问题标题】:Generate calendar of monthly credit fees in JavaScript在 JavaScript 中生成每月信用费用日历
【发布时间】:2016-05-20 14:53:03
【问题描述】:
我有小额信用计算器,我需要将月费日期添加到日历(表格)中。
例如,我有第一次付款日期 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$
如何做到这一点?
【问题讨论】:
标签:
javascript
jquery
date
credits
【解决方案1】:
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;
};