2016-03-31 09:40:55 +08:00
|
|
|
---
|
2016-11-11 12:08:18 +08:00
|
|
|
order: 3
|
2016-07-15 16:20:23 +08:00
|
|
|
title:
|
2016-06-19 11:17:09 +08:00
|
|
|
zh-CN: 日期时间选择
|
2016-11-11 12:08:18 +08:00
|
|
|
en-US: Choose Time
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-06-02 17:20:02 +08:00
|
|
|
|
2016-06-19 11:17:09 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2016-04-15 23:54:47 +08:00
|
|
|
增加选择时间功能,当 `showTime` 为一个对象时,其属性会传递给内建的 `TimePicker`。
|
2015-05-29 21:07:46 +08:00
|
|
|
|
2016-06-19 11:17:09 +08:00
|
|
|
## en-US
|
|
|
|
|
2016-11-11 12:08:18 +08:00
|
|
|
This property provide an additional time selection. When `showTime` is an Object, its properties will be passed on to built-in `TimePicker`.
|
2016-06-19 11:17:09 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2020-07-30 19:17:34 +08:00
|
|
|
import { DatePicker, Space } from 'antd';
|
2022-05-19 09:46:26 +08:00
|
|
|
import type { DatePickerProps, RangePickerProps } from 'antd/es/date-picker';
|
2022-05-23 14:37:16 +08:00
|
|
|
import React from 'react';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2016-11-11 12:08:18 +08:00
|
|
|
const { RangePicker } = DatePicker;
|
2015-05-29 21:07:46 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const onChange = (
|
|
|
|
value: DatePickerProps['value'] | RangePickerProps['value'],
|
|
|
|
dateString: [string, string] | string,
|
|
|
|
) => {
|
2016-09-29 14:35:33 +08:00
|
|
|
console.log('Selected Time: ', value);
|
2016-10-21 15:18:13 +08:00
|
|
|
console.log('Formatted Selected Time: ', dateString);
|
2022-05-19 09:46:26 +08:00
|
|
|
};
|
2015-11-24 17:25:32 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const onOk = (value: DatePickerProps['value'] | RangePickerProps['value']) => {
|
2017-03-07 18:49:22 +08:00
|
|
|
console.log('onOk: ', value);
|
2022-05-19 09:46:26 +08:00
|
|
|
};
|
2017-03-07 18:49:22 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => (
|
2020-07-30 19:17:34 +08:00
|
|
|
<Space direction="vertical" size={12}>
|
2019-12-11 23:32:19 +08:00
|
|
|
<DatePicker showTime onChange={onChange} onOk={onOk} />
|
2016-11-11 12:08:18 +08:00
|
|
|
<RangePicker
|
2017-06-29 11:22:12 +08:00
|
|
|
showTime={{ format: 'HH:mm' }}
|
|
|
|
format="YYYY-MM-DD HH:mm"
|
2016-11-14 19:13:37 +08:00
|
|
|
onChange={onChange}
|
2017-03-07 18:49:22 +08:00
|
|
|
onOk={onOk}
|
2016-11-11 12:08:18 +08:00
|
|
|
/>
|
2022-04-03 23:27:45 +08:00
|
|
|
</Space>
|
2018-11-28 15:00:03 +08:00
|
|
|
);
|
2022-05-19 09:46:26 +08:00
|
|
|
|
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|