Material-ui: DatePicker format

Created on 20 Aug 2015  路  7Comments  路  Source: mui-org/material-ui

This is more a question than a issue, someone can show me a example of how can i change de dateformat to YYYY/MM/DD

I think that the demo page need this example to.

docs v0.x

Most helpful comment

You need to pass a function that takes a Date and returns a String:

formatDate(date){
  return date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate();
}

render(){
  return <DatePicker formatDate={this.formatDate} />;
}

EDIT: fixed formatting

All 7 comments

You've probably solved this by now, but in case someone else has the same issue, there is an optional 'formatDate' prop on DatePicker which the date will be passed through on its way to the TextField.

I still have not solved, the props are there but I would like to see a working example, it say you have to pass a function but not in what format.

You need to pass a function that takes a Date and returns a String:

formatDate(date){
  return date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate();
}

render(){
  return <DatePicker formatDate={this.formatDate} />;
}

EDIT: fixed formatting

So what does formatDate do?

The documentation was greatly improved since this issue was opened. https://github.com/callemall/material-ui/pull/3417 is also adding an example on how to do it.

Hi every one, I am using material ui date-picker from material ui core. It shows january12th(for example) like this I want this format to dd/mm/yy. format. I set initially new Date(); .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mb-copart picture mb-copart  路  3Comments

FranBran picture FranBran  路  3Comments

ghost picture ghost  路  3Comments

reflog picture reflog  路  3Comments

iamzhouyi picture iamzhouyi  路  3Comments