Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 反应日期选择器返回无效日期_Javascript_Reactjs_React Datepicker - Fatal编程技术网

Javascript 反应日期选择器返回无效日期

Javascript 反应日期选择器返回无效日期,javascript,reactjs,react-datepicker,Javascript,Reactjs,React Datepicker,在谷歌浏览器中,一切正常。当我在mozilla React中打开应用程序时,日期选择器返回无效日期 我试图使用时刻(this.state.startDate.toDate() 新日期(this.state.startDate)但它不起作用 class Example extends React.Component { state = { startDate: new Date() }; handleChange = date => { this.setStat

在谷歌浏览器中,一切正常。当我在mozilla React中打开应用程序时,日期选择器返回无效日期

我试图使用
时刻(this.state.startDate.toDate()

新日期(this.state.startDate)
但它不起作用

class Example extends React.Component {
  state = {
    startDate: new Date()
  };

  handleChange = date => {
    this.setState({
      startDate: date
    });
  };

  render() {

    return (
      <DatePicker
        selected={this.state.startDate}
        onChange={this.handleChange}
      />
    );
  }
}
类示例扩展了React.Component{
状态={
起始日期:新日期()
};
handleChange=日期=>{
这是我的国家({
开始日期:日期
});
};
render(){
返回(
);
}
}

尝试添加dateFormat属性,如:

      <DatePicker
        selected={this.state.startDate}
        onChange={this.handleChange}
        dateFormat="d MMM yyyy"
      />

您可以尝试这种方法。该代码在我的Mozilla、chrome和edge项目中运行良好。我的日期选择器版本是
“react datepicker”:“^2.7.0”
,react版本是
“react”:“^16.8.6”

过滤器:{
开始日期:新日期(),
endDate:新日期(),
类型:props.location.state==未定义?0:props.location.state.reportType,
reportName:'未选择',
reportPreviewCount:0,
报告序列号:-1,
用户类型:“0”,
},    
handleChangeDate(日期,日期类型){
让oldState=this.state.filters;
如果(日期类型=='startDate'){
oldState['startDate']=日期;
oldState['reportPreviewCount']=0;
}否则{
oldState['endDate']=日期;
oldState['reportPreviewCount']=0;
}
this.setState({titleDatatable:[],dataSetDataable:[],filters:oldState,flashState:true});
}     
props.handleChangeDate(日期,'startDate')}
className=“表单控件”
下个月
showMonthDropdown
ShowYear下拉列表
dropdownMode=“选择”
onChangeRaw={(e)=>e.preventDefault()}
withPortal
/>

控制台中的错误是什么?@MukeshPrajapati error:“无效日期”您使用的react datepicker的版本是什么?Mozilla的版本是什么?日期是什么?如果是事件,请使用
startDate:event.target.value
@DenysKozak“react datepicker”:“^2.6.0”、firefox quantum 68.0.2(64位)mozilla firefox dla Ubuntuer:“无效时间”尝试立即启动。liek startDate:moment(),endDate:moment()。在“react”:“^16.6.3”和“react datepicker”:“1.6.0”,我使用了moment,您的react和datetime pickerin版本是什么
filters:{
                    startDate: new Date(),
                    endDate: new Date(),
                    type: props.location.state === undefined ? 0 : props.location.state.reportType,
                    reportName : 'Not Selected',
                    reportPreviewCount: 0,
                    reportedUserId: -1,
                    userType: '0',
                },    


    handleChangeDate(date, dateType) {
            let oldState = this.state.filters;

            if(dateType === 'startDate'){
                oldState['startDate'] = date;
                oldState['reportPreviewCount'] = 0;

            }else{
                oldState['endDate'] = date;
                oldState['reportPreviewCount'] = 0;
            }
            this.setState({titleDatatable: [], dataSetDataable: [], filters: oldState, flashState: true});
        }     


                          <DatePicker
                                selected= {props.filters.startDate}
                                onChange={(date) => props.handleChangeDate(date, 'startDate')}
                                className="form-control"
                                peekNextMonth
                                showMonthDropdown
                                showYearDropdown
                                dropdownMode="select"
                                onChangeRaw={(e) => e.preventDefault()}
                                withPortal
                            />