Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.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
Reactjs React ant设计日期时间选择器值单独保存_Reactjs_Antd_React Typescript - Fatal编程技术网

Reactjs React ant设计日期时间选择器值单独保存

Reactjs React ant设计日期时间选择器值单独保存,reactjs,antd,react-typescript,Reactjs,Antd,React Typescript,我正在为使用react typescript项目,我能知道如何使用两个标签保存日期和时间值吗 有什么解决办法吗 这里是我的代码 interface AppProps { } interface AppState { name: string; date: Date; } class App extends Component<AppProps, AppState> { constructor(props) { super(props); this.st

我正在为使用react typescript项目,我能知道如何使用两个标签保存日期和时间值吗

有什么解决办法吗

这里是我的代码

interface AppProps { }
interface AppState {
  name: string;
  date: Date;
}

class App extends Component<AppProps, AppState> {
  constructor(props) {
    super(props);
    this.state = {
      name: 'React',
      date: new Date()
    };
  }
//date disable
    disabledDate(current: any) {
        // Can not select days before today and today
        //return current && current < moment().endOf('day');
        return current && current < moment().startOf("day")
    }

    //time disable
    getDisabledHours() {
        var hours = [];
        for (let i = 0; i < moment().hour(); i++) {
            hours.push(i);
        }
        return hours;
    }

    //time disable
    getDisabledMinutes = (selectedHour: any) => {
        var minutes = [];
        if (selectedHour === moment().hour()) {
            for (var i = 0; i < moment().minute(); i++) {
                minutes.push(i);
            }
        }
        return minutes;
    }
接口AppProps{}
接口应用状态{
名称:字符串;
日期:日期;
}
类应用程序扩展组件{
建造师(道具){
超级(道具);
此.state={
名称:'反应',
日期:新日期()
};
}
//日期禁用
禁用数据(当前:任何){
//不能选择今天之前的日期和今天
//返回当前值和当前值<力矩().endOf('day');
返回电流和电流<力矩().startOf(“日”)
}
//时间禁用
getDisabledHours(){
var小时数=[];
for(设i=0;i{
var分钟=[];
如果(selectedHour==矩().hour()){
对于(var i=0;i

render(){
返回(
this.setState({date:d})}
样式={{width:“100%”}
showTime={{disabledMinutes:moment().date()
);
}
}

试试这个,它正在工作

   getData = (date) => {
     console.log('date', date);
     console.log("date",moment(date).format('YYYY-MM-DD'));
     console.log("time",moment(date).format('HH:mm:ss'))
   }

    render() {
        return (
            <div>
                <DatePicker
                    name="Date" disabledDate={this.disabledDate}
                    onChange={this.getData}
                    style={{ width: "100%" }}
                    showTime={{
                        disabledMinutes: moment().date() < moment(this.state.date).date() ? undefined : this.getDisabledMinutes,
                        disabledHours: moment().date() < moment(this.state.date).date() ? undefined : this.getDisabledHours
                    }}
                    value={moment(this.state.date)}

                />
            </div>
        );
    }
getData=(日期)=>{
console.log(“日期”,日期);
console.log(“日期”,时刻(日期).format('YYYY-MM-DD');
log(“时间”、时刻(日期).format('HH:mm:ss'))
}
render(){
返回(
);
}

希望这能对您有所帮助。

感谢您的解决方案获得帮助me@core114很高兴能帮上忙!!
   getData = (date) => {
     console.log('date', date);
     console.log("date",moment(date).format('YYYY-MM-DD'));
     console.log("time",moment(date).format('HH:mm:ss'))
   }

    render() {
        return (
            <div>
                <DatePicker
                    name="Date" disabledDate={this.disabledDate}
                    onChange={this.getData}
                    style={{ width: "100%" }}
                    showTime={{
                        disabledMinutes: moment().date() < moment(this.state.date).date() ? undefined : this.getDisabledMinutes,
                        disabledHours: moment().date() < moment(this.state.date).date() ? undefined : this.getDisabledHours
                    }}
                    value={moment(this.state.date)}

                />
            </div>
        );
    }