JavaScript: how to convert a date in custom format to Date object

Let's  consider the case that you have a date “08/25/2022” and you want to use in a new Date() object. The problem is that this date format cannot be passed to new Date(), because there will either be an error or the final date value won't be correct.

First you need to convert the date to the other format.

An example:

var splittedDate = "25.08.2022".split(".");  
var formattedDate = splittedDate[1] + "/" + splittedDate[0] + "/" + splittedDate[2];
var finDate = new Date(formattedDate);


No comments yet, you can leave yours: