Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change format date on Datepicker (material-ui)

I want to change the format of the date on DatePicker (material-ui-pickers), but when I use the formatDate feature, the format of the date does not change and still show only month and date, not the year selected.

This is my code:

<DatePicker
  margin="normal"
  disableFuture
  openTo="year"
  views={["year", "month", "day"]}
  value={selectedDate}
  onChange={this.handleDateChange}
  maxDate={maxdate}
  formatDate={(date) => moment(date).format('DD-MM-YYYY')}
/>
like image 549
emjea Avatar asked Mar 04 '26 12:03

emjea


2 Answers

The prop for changing the date format is called format and takes a string instead of a function.

<DatePicker
  margin="normal"
  disableFuture
  openTo="year"
  views={["year", "month", "day"]}
  value={selectedDate}
  onChange={this.handleDateChange}
  maxDate={maxdate}
  format="DD-MM-YYYY"
/>
like image 130
Tholle Avatar answered Mar 06 '26 03:03

Tholle


2022 method is:

<DatePicker inputFormat="MM/dd/yyyy" />

like image 28
Victor Ross Avatar answered Mar 06 '26 01:03

Victor Ross



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!