Uncaught Error: Invalid date: 21/01/2023 using DateTIme Picker in React
P粉103739566
P粉103739566 2024-03-30 22:58:54
0
1
314

I can't tell what the problem is here because I have implemented the react datetime picker as per the documentation, but when I select a date it shows an invalid date Uncaught Error: Invalid date: 17/01/ 2023 , what did I do wrong

import DateTimePicker from 'react-datetime-picker';
function ServiceDetail() {
    const [date, setDate] = useState(new Date());
    return (
      <DateTimePicker
        className="float-start"
        style={{ border: "none" }}
        value={date}
        dateFormat="dd/MM/yyyy"
        onChange={(date) => {
          const d = new Date(date).toLocaleDateString("fr-FR");
          console.log(d);
          setDate(d);
        }}
    name="booking_date"
/>;
)

I added more attributes based on SO's ans https://stackoverflow.com/a/70183380/15178267

P粉103739566
P粉103739566

reply all(1)
P粉270891688
const [date, setDate] = useState(new Date().toLocaleDateString('fr-FR'));

You should change this line again and it will work

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!