2016-11-11 12:08:18 +08:00
|
|
|
---
|
|
|
|
order: 1
|
|
|
|
title:
|
|
|
|
zh-CN: 日期格式
|
|
|
|
en-US: Date Format
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
使用 `format` 属性,可以自定义日期显示格式。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
We can set the date format by `format`.
|
|
|
|
|
2017-01-19 15:19:03 +08:00
|
|
|
````__react
|
2016-11-11 12:08:18 +08:00
|
|
|
import { DatePicker } from 'antd';
|
|
|
|
import moment from 'moment';
|
|
|
|
const { MonthPicker, RangePicker } = DatePicker;
|
|
|
|
|
|
|
|
const dateFormat = 'YYYY/MM/DD';
|
|
|
|
const monthFormat = 'YYYY/MM';
|
|
|
|
ReactDOM.render(
|
|
|
|
<div>
|
2016-11-14 19:13:37 +08:00
|
|
|
<DatePicker defaultValue={moment('2015/01/01', dateFormat)} format={dateFormat} />
|
|
|
|
<br />
|
|
|
|
<MonthPicker defaultValue={moment('2015/01', monthFormat)} format={monthFormat} />
|
|
|
|
<br />
|
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
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
, mountNode);
|
2016-11-11 12:08:18 +08:00
|
|
|
````
|