create new date from string 13.11.2022 currently i got invalid date in javascript

You can use the Date.parse() method to parse a string into a Date object, but it only supports a limited number of date formats. In your case, you need to first convert the string to a supported format before parsing it.

Here's an example of how to do it using the split() method to extract the day, month, and year components from the string, and then creating a new date object using the Date() constructor:

index.tsx
const dateString = '13.11.2022';
const parts = dateString.split('.');
const year = parts[2];
const month = parts[1] - 1; // months are zero-based in Date constructor
const day = parts[0];
const date = new Date(year, month, day);
229 chars
7 lines

Now date contains a valid Date object representing the 13th of November 2022.

gistlibby LogSnag