RangePicker
is not getting values after using moment. It gets null values even if we click on the date range. But if we don't use the moment, it displays values (not human-readable format).But after converting using the moment library, it gets null values.
import {DatePicker} from 'antd';
const{RangePicker}=DatePicker;
function selectTimeSlots(values){
console.log(moment(values[0].format('MMM DD YYYY HH:mm'))
console.log(moment(values[1]).format('MMM DD YYYY HH:mm'))
//after converting it doesn't get values
}
<RangePicker showTime={{format : 'HH:mm'}} format='MMM DD YYYY HH:mm' onChange={selectTimeSlots}/>
I try to write it as like this but it also didn't work. After using moment it does not working.
console.log(moment(values[0],'MMM DD YYYY HH:mm'))
I found the answer. I hope this answer will be helpful for anyone who got this problem.
If you're having issues with the moment library, it might be due to the fact that it is now considered as a legacy library and is no longer recommended for use by its creators. Instead, they recommend using the day.js
or Luxon
libraries, which are more modern and offer similar functionality.
import dayjs from 'dayjs';
function selectTimeSlots(values){
console.log(dayjs (values[0].format('MMM DD YYYY HH:mm'))
console.log(dayjs (values[1]).format('MMM DD YYYY HH:mm'))
}
Replace day.js
with moment keyword.