RangeError: Invalid time value #2928
-
Hello, I'm trying to convert the following code from moment to date-fns and I get the following message: "RangeError: Invalid time value". Can you help me ? import moment from 'moment'; {console.log(myDate)} Conversion test to date-fns: import { format } from 'date-fns'; { result => 370 | var originalDate = toDate(dirtyDate);
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Your conversion seems OK to me, I can't reproduce the problem: import moment from "moment";
import { format } from "date-fns";
const myDate = "2022-01-14T07:57:57.288+0000";
const r1 = moment(myDate).format("DD/MM/YYYY");
console.log(r1); // 14/01/2022
const r2 = format(new Date(myDate), "dd/MM/yyyy");
console.log(r2); // 14/01/2022 The error message you are getting implies that you are not passing a valid input in the Date constructor, so maybe double check that |
Beta Was this translation helpful? Give feedback.
-
I just managed this with a ternary for now while waiting for the date of the date to load nicely. I'll come back to that later. What emerges from my problem date fns does more control than moment especially on the structure of the date received! |
Beta Was this translation helpful? Give feedback.
I just managed this with a ternary for now while waiting for the date of the date to load nicely. I'll come back to that later. What emerges from my problem date fns does more control than moment especially on the structure of the date received!