angular - 我可以在时刻 js 中得到今天的日期加上一个月吗?
问题描述
我有一个获取今天日期的 ion-datetime 输入。我需要在今天后一个月动态设置最大日期。我可以使用 moment.js 实现这一点吗?
这是我的输入:
<ion-datetime display-format="MMMM YYYY" max=" ONE MONTH AFTER TODAY??"></ion-datetime>
解决方案
<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
推荐阅读
- html - 如何访问我上传到 000webhost 网站的所有 HTML 文件的 URL
- javascript - TypeError: query.findAll 不是函数节点 js mysql
- firebase - Firebase 'to' 发送给 Flutter 中的每个人
- python - 为什么 Keras MAPE 指标在训练期间呈爆炸式增长,而 MSE 损失却没有?
- asp.net-core - 登录 ASP.NET Core Main
- influxdb - InfluxQL 到 Flux
- javascript - 切换语句如何与字符串一起工作?
- verilog - 执行具有相同值的 Always Blocks
- reporting-services - 在 Blazor 服务器应用程序中显示 SSRS 报告(免费)
- swift - 如何在 Swift 中更改 ImageView 的颜色?