How to resolve this "TypeError: date.locale"? I’m making an attempt to address this problem, but despite my efforts, I’m unable to find a solution.
API response:
{
"birthday": "1999-03-09T00:00:00.000Z"
}
change date format
useEffect(() => {
if (currentRecord) {
const formattedBirthday = dayjs(currentRecord.birthday)
.tz("Asia/Dhaka")
.format("YYYY-MM-DD");
setCurrentRecord({
...currentRecord,
birthday: formattedBirthday,
});
form.setFieldsValue({
birthday: moment(formattedBirthday),
});
}
}, [currentRecord, setCurrentRecord, form]);
new date: birthday: "1999-03-09"
JSX –
<Form.Item
label="Birthday"
name="birthday"
rules={[
{ required: true, message: "Please select a birthday!" }
]}
>
<DatePicker
style={{ width: "100%" }}
placeholder="Select your birthday"
format={dateFormat}
/>
</Form.Item>
2
Answers
there needs to be a pass date as an object
here is the code:
The problem is that you’re using
moment
withdayjs
. Following docs you should use onlydayjs
to handle time related values: