ant-design/components/date-picker/demo/format.md

43 lines
931 B
Markdown
Raw Normal View History

---
order: 1
title:
zh-CN: 日期格式
en-US: Date Format
---
## zh-CN
使用 `format` 属性,可以自定义日期显示格式。
## en-US
We can set the date format by `format`.
2017-02-13 10:55:53 +08:00
````jsx
import { DatePicker } from 'antd';
import moment from 'moment';
2018-06-27 15:55:04 +08:00
const { MonthPicker, RangePicker } = DatePicker;
const dateFormat = 'YYYY/MM/DD';
const monthFormat = 'YYYY/MM';
const dateFormatList = ['DD/MM/YYYY','DD/MM/YY']
ReactDOM.render(
<div>
2016-11-14 19:13:37 +08:00
<DatePicker defaultValue={moment('2015/01/01', dateFormat)} format={dateFormat} />
<br />
<DatePicker defaultValue={moment('01/01/2015', dateFormatList[0])} format={dateFormatList} />
2016-11-14 19:13:37 +08:00
<br />
<MonthPicker defaultValue={moment('2015/01', monthFormat)} format={monthFormat} />
<br />
<RangePicker
defaultValue={[moment('2015/01/01', dateFormat), moment('2015/01/01', dateFormat)]}
format={dateFormat}
2016-11-14 19:13:37 +08:00
/>
2018-06-27 15:55:04 +08:00
</div>,
2018-11-28 15:00:03 +08:00
mountNode
);
````