使用setDate(),如果传入的值大于本月的天数,则javascript将从本月的第一天开始计数,那么使用使用setDate(28)方法,则并不是表示1月15号之后的28天,而是表示距离1月1日之后的28天,如果我们要计算的是当前日期之后的28天,就需要先取出当前的天数,再用当前的天数加上28。因此,要计算1月15日之后的28天,应该使用setDate(15+28)。
如果我们想获得当前日期之前的28天,只需要用当前的日期减去28即可。
类似的方法和原则也适用于setMonth()方法。