【问题标题】:Can I get today’s date plus one month in moment js? [duplicate]我可以在moment js中得到今天的日期加上一个月吗? [复制]
【发布时间】:2019-09-28 22:12:30
【问题描述】:
我有一个获取今天日期的 ion-datetime 输入。我需要在今天后一个月动态设置最大日期。
我可以使用 moment.js 来实现吗?
这是我的输入:
<ion-datetime display-format="MMMM YYYY" max=" ONE MONTH AFTER TODAY??"></ion-datetime>
【问题讨论】:
标签:
angular
ionic-framework
momentjs
【解决方案1】:
<ion-datetime displayFormat="MMMM YY" min="{{min}}" max="{{max}}"></ion-datetime>
现在你需要最小值和最大值。
首先,让我们来看看今天和下个月。
const today = moment(new Date()).format('YYYY-MM-DD');
const nextMonth = moment(today).add(1, 'M');
var nextMonthEnd = moment(nextMonth).endOf('month');
if(today.date() != nextMonth.date() && nextMonth.isSame(nextMonthEnd.format('YYYY-MM-DD'))) {
nextMonth = nextMonth.add(1, 'd');
}
console.log(today.format('DD-MM-YYYY'));
console.log(nextMonth.format('DD-MM-YYYY'));
现在
this.min = this.today;
this.max = this.nextMonth