更改材质ui的日期选择器中的formatDate [英] Change formatDate in datepicker of material ui
问题描述
i使用具有redux形式的material-ui datepicker组件.我在这里有一个小问题,看起来很棒.当我更改日期时,它在我的输入字段中显示为yyyy-mm-dd.我想更改它以显示为dd-mm-yyyy.日期选择器具有一个名为formatDate的属性,该属性将一个函数作为输入. 所以我写道:
i using material-ui datepicker component with redux form. It looks amazing by i have a little issue here. When i change the date it appears in my input field as yyyy-mm-dd. I want to change it so as to appear as dd-mm-yyyy. The datepicker has a property called formatDate which takes a function as an input. So i wrote:
<Field
name="dateFrom"
component={DatePicker}
hintText="Ημερομηνία από"
autoOk
formatDate={() => moment().format(DD-MM-YYYY)}
/>
但是它似乎不起作用.你有什么主意吗?
but it does not seem to work. Do you have any ideas?
推荐答案
As per DOC:
formatDate ====> 函数 ====>调用此函数进行格式化 输入字段中显示的日期,并应返回一个字符串.
formatDate ====> function ====> This function is called to format the date displayed in the input field, and should return a string.
签名:函数(日期:对象)=>任何日期:日期对象为 格式化.返回(任意):格式化日期.
Signature: function(date: object) => any date: Date object to be formatted. returns (any): The formatted date.
将选定的日期作为formatDate函数的参数接收,更改日期的格式并将格式化程序的值作为字符串返回.
Receive the selected date as an argument of formatDate function, change the format of the date and return the formatter value as a string.
另一个变化是:
format(DD-MM-YYYY)
DD-MM-YYYY
应该是这样的字符串:
DD-MM-YYYY
should be a string like this:
format('DD-MM-YYYY')
这样写:
<Field
name="dateFrom"
component={DatePicker}
hintText="Ημερομηνία από"
autoOk
formatDate={(date) => moment(date).format('DD-MM-YYYY')}
/>
这篇关于更改材质ui的日期选择器中的formatDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!