2016-11-11 12:08:18 +08:00
|
|
|
---
|
2019-12-11 23:32:19 +08:00
|
|
|
order: 2
|
2016-11-11 12:08:18 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 日期格式
|
|
|
|
en-US: Date Format
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
使用 `format` 属性,可以自定义日期显示格式。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
We can set the date format by `format`.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2020-07-30 19:17:34 +08:00
|
|
|
import { DatePicker, Space } from 'antd';
|
2016-11-11 12:08:18 +08:00
|
|
|
import moment from 'moment';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
const { RangePicker } = DatePicker;
|
2016-11-11 12:08:18 +08:00
|
|
|
|
|
|
|
const dateFormat = 'YYYY/MM/DD';
|
|
|
|
const monthFormat = 'YYYY/MM';
|
2019-03-01 13:50:28 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
const dateFormatList = ['DD/MM/YYYY', 'DD/MM/YY'];
|
2019-03-01 13:50:28 +08:00
|
|
|
|
2016-11-11 12:08:18 +08:00
|
|
|
ReactDOM.render(
|
2020-07-30 19:17:34 +08:00
|
|
|
<Space direction="vertical" size={12}>
|
2016-11-14 19:13:37 +08:00
|
|
|
<DatePicker defaultValue={moment('2015/01/01', dateFormat)} format={dateFormat} />
|
2019-03-01 13:50:28 +08:00
|
|
|
<DatePicker defaultValue={moment('01/01/2015', dateFormatList[0])} format={dateFormatList} />
|
2019-12-11 23:32:19 +08:00
|
|
|
<DatePicker defaultValue={moment('2015/01', monthFormat)} format={monthFormat} picker="month" />
|
2016-11-11 12:08:18 +08:00
|
|
|
<RangePicker
|
|
|
|
defaultValue={[moment('2015/01/01', dateFormat), moment('2015/01/01', dateFormat)]}
|
|
|
|
format={dateFormat}
|
2016-11-14 19:13:37 +08:00
|
|
|
/>
|
2020-07-30 19:17:34 +08:00
|
|
|
</Space>,
|
2019-05-07 14:57:32 +08:00
|
|
|
mountNode,
|
2018-11-28 15:00:03 +08:00
|
|
|
);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|