我最初想显示上个月的最后日期,例如,这是11月,我想显示31/10/2019。怎么可能?
var date = new Date();
date.setMonth(date.getMonth())
const firstDayOfCurrent = new Date(date.getFullYear(), date.getMonth(), 0);
const firstDayOfCurrentMonth = moment(firstDayOfCurrent).format('MM/DD/YYYY')
console.log(firstDayOfCurrentMonth);
<td><input type="date" value={firstDayOfCurrentMonth} onChange={(e) => { this.state.invoice.InvoiceDateString = e.target.value; this.setState({ isset: true }); }} required /></td>
答案 0 :(得分:1)
您可以从当前日期开始一个月到当前月份的第一天,然后减去一天:
const today = new Date();
const firstDayOfCurrentMonth = new Date(today.getFullYear(), today.getMonth(), -1);
``
答案 1 :(得分:1)
此代码段将为您提供上个月的最后日期
var date = new Date();
date.setMonth(date.getMonth())
var lastDay = new Date(date.getFullYear(), date.getMonth(), 0);
var lastDayOfLastMonth = lastDay.toISOString().substr(0, 10);
和您的输入标签
<input type="date" defaultValue={lastDayOfLastMonth } required />
答案 2 :(得分:0)