今天在找一个追加天数的方法。百度N久。找到了一个JS库。叫JSFunction。兴奋半天。
发现里面的追加方法也不好。就改了他的function内容。
废话不多说。代码贴出来。跟大家分享下心得
回头再给他加一个减天数的方法。还有月 周 年等。敬请期待
/*
以当前日期为基础。追加天数
d:要追加的天数
用法:$.date().addDays(1);
*/
Date.fn("addDays", function (d) {
var dayNumber = new Date(this.getYear(), this.getMonth() + 1, 0).getDate(); //当月天数
var Year = this.getYear(); //当前年
var Month = this.getMonth() + 1; //当前月
var Day = this.getDate(); //当前日
for (var i = 0; i < d; i++) {
Day++;
if (Day > dayNumber) {
Day = 1;
Month++;
if (Month > 12) {
Month = 1;
Year++;
}
}
}
return new Date(Year, Month - 1, Day);
});