2015-11-24 17:25:32 +08:00
|
|
|
# 日期时间选择
|
2015-05-29 21:07:46 +08:00
|
|
|
|
|
|
|
- order: 4
|
2015-06-02 17:20:02 +08:00
|
|
|
|
2015-11-24 17:25:32 +08:00
|
|
|
和 [时间选择框](/components/timepicer) 配合使用。
|
2015-05-29 21:07:46 +08:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
````jsx
|
2015-11-24 17:25:32 +08:00
|
|
|
import { Datepicker, Timepicker } from 'antd';
|
2015-05-29 21:07:46 +08:00
|
|
|
|
2015-11-24 17:25:32 +08:00
|
|
|
let result = new Date();
|
|
|
|
let selectdDate, selectdTime;
|
|
|
|
function handleChange(from, value) {
|
|
|
|
if (!value) {
|
|
|
|
from === 'date' ?
|
|
|
|
(selectdDate = false) : (selectdTime = false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (from === 'date') {
|
|
|
|
result.setFullYear(value.getFullYear());
|
|
|
|
result.setMonth(value.getMonth());
|
|
|
|
result.setDate(value.getDate());
|
|
|
|
selectdDate = true;
|
|
|
|
} else {
|
|
|
|
result.setHours(value.getHours());
|
|
|
|
result.setMinutes(value.getMinutes());
|
|
|
|
result.setSeconds(value.getSeconds());
|
|
|
|
selectdTime = true;
|
|
|
|
}
|
|
|
|
if (selectdDate && selectdTime) {
|
|
|
|
console.log('选择结果是:' + result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(<div>
|
|
|
|
<Datepicker onChange={handleChange.bind(null, 'date')} />
|
|
|
|
<Timepicker onChange={handleChange.bind(null, 'time')} />
|
|
|
|
</div>, document.getElementById('components-datepicker-demo-time'));
|
2015-05-29 21:07:46 +08:00
|
|
|
````
|