1

I am working on a project with Fluent UI and React JSX and my question is how to format date of DatePicker component to be day.month.year format?

Example:

<DatePicker
  ...
  formatDate={(date) => {
    return (date.getMonth() + "." + date.getDate() + "." + date.getFullYear)
  }}
/>
MartinT
  • 590
  • 5
  • 21
Ștefania
  • 11
  • 1
  • 2
  • Hi @Ștefania and welcome to SO. When you ask a question put your code as text not as picture, or provide Codepen/JSFiddle working example. – Marko Savic Dec 06 '21 at 10:43

1 Answers1

1

If you want to format date of DatePicker Component use formatDate method:

const formatDate = (date?: Date): string => {
  if (!date) return '';
  const month = date.getMonth() + 1; // + 1 because 0 indicates the first Month of the Year.
  const day = date.getDate();
  const year = date.getFullYear();

  return `${day}.${month}.${year}`;
}

<DatePicker
  ...
  formatDate={formatDate}
/>

Codepen working example.

Useful links:

DatePicker documentation

MDN Date Object

Marko Savic
  • 2,159
  • 2
  • 14
  • 27