afc163
9 years ago
2 changed files with 31 additions and 7 deletions
@ -1,15 +1,40 @@ |
|||
# 时间选择 |
|||
# 日期时间选择 |
|||
|
|||
- order: 4 |
|||
|
|||
准确到秒的时间选择面板。 |
|||
和 [时间选择框](/components/timepicer) 配合使用。 |
|||
|
|||
--- |
|||
|
|||
````jsx |
|||
import { Datepicker } from 'antd'; |
|||
import { Datepicker, Timepicker } from 'antd'; |
|||
|
|||
ReactDOM.render( |
|||
<Datepicker showTime={true} format="yyyy-MM-dd HH:mm:ss" defaultValue="2015-11-11 11:11:11"/> |
|||
, document.getElementById('components-datepicker-demo-time')); |
|||
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')); |
|||
```` |
|||
|
Loading…
Reference in new issue