例子:
- 现在是 2012 年 3 月 26 日。我要求明年 2 月。它应该返回 2013-01-01
- 现在是 2012 年 3 月 26 日。我要求明年 4 月。它应该返回 2012-04-01
你可以做这样的事情。
// date is a JS date or moment
// month is the zero indexed month (0 - 11)
function nextMonth(date, month) {
var input = moment(date);
var output = input.clone().startOf('month').month(month);
return output > input ? output : output.add(1, 'years');
}
请参阅有关操纵力矩的文档。http://momentjs.com/docs/#/manipulated/ http://momentjs.com/docs/#/manipulating/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)