我在反应中使用了airbnb daterange选择器。
<DateRangePicker
startDate={this.state.startDate} // momentPropTypes.momentObj or null,
startDateId="your_unique_start_date_id" // PropTypes.string.isRequired,
endDate={this.state.endDate} // momentPropTypes.momentObj or null,
endDateId="your_unique_end_date_id" // PropTypes.string.isRequired,
onDatesChange={({ startDate, endDate }) => {
this.setState({ startDate, endDate });
}} // PropTypes.func.isRequired,
focusedInput={this.state.focusedInput} // PropTypes.oneOf([START_DATE, END_DATE]) or null,
onFocusChange={focusedInput => this.setState({ focusedInput })} // PropTypes.func.isRequired,
daySize={50}
noBorder={true}
isOutsideRange={() => false}
/>
选择日期时,我还会收到带有时间部分的日期,例如:
如果我选择6月26日,我将会得到:
{26/06/2019 12:00:00}
所以我怎么只能得到{26/06/2019 00:00:00}
谢谢大家 干杯
答案 0 :(得分:0)
您的问题与React无关。
我猜在写{26/06/2019 12:00:00}
时,您的意思是字符串:"26/06/2019 12:00:00"
或Date
实例:
const endDateString = "26/06/2019 12:00:00";
const dateRegex = /\d{1,2}\/\d{1,2}\/\d{4}/g
const dateString = endDateString.match(dateRegex);
console.log(endDateString); // ["26/06/2019"]
const endDate = new Date('June 26, 2019 12:00:00');
const fromInstance = `${endDate.getDate()}/${endDate.getMonth()}/${endDate.getFullYear()}`
console.log(fromInstance);