Change formatDate in datepicker of material ui

浪子不回头ぞ 提交于 2019-12-01 18:08:39

问题


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?


回答1:


As per DOC:

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.


Receive the selected date as an argument of formatDate function, change the format of the date and return the formatter value as a string.

Another change is:

format(DD-MM-YYYY)

DD-MM-YYYY should be a string like this:

format('DD-MM-YYYY')

Write it like this:

<Field
      name="dateFrom"
      component={DatePicker}
      hintText="Ημερομηνία από"
      autoOk
      formatDate={(date) => moment(date).format('DD-MM-YYYY')}
/>


来源:https://stackoverflow.com/questions/46543391/change-formatdate-in-datepicker-of-material-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!