2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 4
|
|
|
|
hidden: true
|
2016-06-19 11:17:09 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 日期时间选择二
|
|
|
|
en-US: To select a date, case 2
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-12-25 15:34:32 +08:00
|
|
|
|
2016-06-19 11:17:09 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2016-03-31 09:40:55 +08:00
|
|
|
和 <a href="/components/time-picker">时间选择框</a> 配合使用。
|
2015-12-25 15:34:32 +08:00
|
|
|
|
2016-06-19 11:17:09 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
Cooperate with `<a href="/components/time-picker">time-picker</a>`
|
|
|
|
|
2015-12-25 15:34:32 +08:00
|
|
|
````jsx
|
|
|
|
import { DatePicker, TimePicker } from 'antd';
|
|
|
|
|
|
|
|
const DateTimePicker = React.createClass({
|
|
|
|
handleChange(from, value) {
|
|
|
|
this.result = this.result || new Date();
|
|
|
|
if (!value) {
|
|
|
|
if (from === 'date') {
|
|
|
|
this.selectedDate = false;
|
|
|
|
} else {
|
|
|
|
this.selectedTime = false;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (from === 'date') {
|
|
|
|
this.result.setFullYear(value.getFullYear());
|
|
|
|
this.result.setMonth(value.getMonth());
|
|
|
|
this.result.setDate(value.getDate());
|
|
|
|
this.selectedDate = true;
|
|
|
|
} else {
|
|
|
|
this.result.setHours(value.getHours());
|
|
|
|
this.result.setMinutes(value.getMinutes());
|
|
|
|
this.result.setSeconds(value.getSeconds());
|
|
|
|
this.selectedTime = true;
|
|
|
|
}
|
|
|
|
if (this.selectedDate && this.selectedTime) {
|
|
|
|
this.props.onSelect(this.result);
|
|
|
|
}
|
|
|
|
},
|
2016-03-30 17:06:19 +08:00
|
|
|
handleDateChange(value) {
|
|
|
|
this.handleChange('date', value);
|
|
|
|
},
|
|
|
|
handleTimeChange(value) {
|
|
|
|
this.handleChange('time', value);
|
|
|
|
},
|
2015-12-25 15:34:32 +08:00
|
|
|
render() {
|
2016-01-07 16:29:12 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2016-03-30 17:06:19 +08:00
|
|
|
<DatePicker onChange={this.handleDateChange} />
|
|
|
|
<TimePicker onChange={this.handleTimeChange} />
|
2016-01-07 16:29:12 +08:00
|
|
|
</div>
|
|
|
|
);
|
2016-05-11 09:32:33 +08:00
|
|
|
},
|
2015-12-25 15:34:32 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
function onSelect(value) {
|
|
|
|
console.log('选择了时间:', value);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(<DateTimePicker onSelect={onSelect} />
|
2015-12-29 12:08:58 +08:00
|
|
|
, mountNode);
|
2015-12-25 15:34:32 +08:00
|
|
|
````
|