我要檢查,如果當前日期是從2017年7月11日開始日期之間有效期至使用moment.js 2018年5月1日。瞬間的js日期比較
任何幫助?如何做到這一點?
我有下面的代碼:
import React, {Component} from 'react';
import moment from 'moment';
class Dates extends Component {
constructor() {
super();
this.state = {
dateNow: moment(),
availability:''
}
}
componentDidMount() {
let startdate = moment("17-11-2017");
let enddate = moment("05-01-2018");
this.setState({
availability: 'Yes'
});
}
render() {
return(
<div>
<div>{this.state.dateNow}</div>
<table>
<tr>
<td>Available from 7th November,2017 to 5th January,2018?</td>
<td>{this.state.availability}</td>
</tr>
</table>
</div>
);
}
}
export default Dates;
檢查此:https://momentjs.com/docs/#/query/is-between/ –
非常感謝@Ajit – Subhojit
Subhojit請在標記爲bestanswer訪問https:// momentjs之前檢查答案。 com /並在console.log中輸入答案,您在問題中提到的日期必須返回true,但在elumalai_kp中它返回false,因此這是一個無效答案,他的方法是正確的,但回答不正確 –