antd的TimePicker使用方法,设置的defaultValue或value属性应为moment对象,onchange的时候format为标准时间('YYYY-MM-DD HH:mm:ss')后再赋予对应提交的字段。
export default class DetailComponent extends Component { state = { visit_time: null, } componentWillMount(){ this.setState({ visit_time: moment(res.visit_time, 'YYYY-MM-DD HH:mm:ss'), }) } render = () => { return( <FormItem {...formItemLayout} label="回访时间"> {getFieldDecorator('visit_time', { initialValue: this.state.visit_time, rules: [{ type: 'object', required: false}], })( <DatePicker style={{width: '50%'}} showToday={true} showTime={true} format={"YYYY-MM-DD HH:mm:ss"} placeholder={'请选择入驻时间'} onChange={(v) => this.setState({visit_time: v})} /> )} </FormItem> ) } handleReturnVisitSubmit = (e) => { e.preventDefault(); this.props.form.validateFields({ force: true }, (err, values) => { const params = { visit_time: moment(this.state.visit_time).format('YYYY-MM-DD HH:mm:ss'), }; this.setState({ svcSettingSubmitting: true }); api.setServiceOrderReturnVisit(params).then((res) => { this.setState({ svcSettingSubmitting: false }); if (res) { message.success('提交成功!', 1); this.props.form.resetFields(); } }); }); } }
即,传入:moment(res.visit_time, 'YYYY-MM-DD HH:mm:ss')
获取:moment(this.state.visit_time).format('YYYY-MM-DD HH:mm:ss')
中国梦 2018/06/11 19:00
这个有点diao