How do I use the datepicker in React to display numbers on the month selection screen?

Asked 1 years ago, Updated 1 years ago, 348 views

We are implementing a calendar with React-datepicker.
It says Jan for January and Feb for February, but I would like to write numbers for the month instead of English.
If anyone knows how to do it, please let me know.

Enter a description of the image here

reactjs

2022-12-07 07:24

1 Answers

The same question came next.

If implemented accordingly:

import React, {useState} from "react";

import "react-datepicker/dist/react-datepicker.css";
import DatePicker, {registerLocale} from "react-datepicker";
import ja from "date-fns/locale/ja"; // register it with the name you want

registerLocale("ja",ja);

constApp=()=>{
  const [startDate, setStartDate] = useState(newDate());
  return(
    <DatePicker
      locale="ja"
      selected = {startDate}
      onChange={(date)=>setStartDate(date)}
      dateFormat = "yyyy/MM"
      showMonthYearPicker
    />
  );
};

export default App;

Code samples


2022-12-07 07:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.