简体   繁体   中英

The date is not getting updated in in Datetime picker in reactjs but time is getting updated as per user selected fucntional compoenent reactjs

I have taken a datetime picker for taking date and time with same input. I used moment for changing the format but when I am displaying date on my website my time is as per user selected but my date is not as per user selected it is some random number. Could you please help with this problem.

   const [value, setValue] = useState(new Date());
   <DateTimePicker
      onChange={setValue}
       value={value}
        format="dd-MM-yyyy hh:mm a" />

I am printing this in map function of reactjs.

   <p><span style={{fontSize:12}}>{moment(item.value).format('d MMM,h:mm A')}</span> 
    </p>
     

try giving the moment format of the date for example

<p><span style={{fontSize:12}}>{moment(item.value,'dd-MM-yyyy hh:mm a').format('d MMM,h:mm A')}</span></p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM