Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[JavaScript] Create date object from date string dd.MM.yyyy

Using regex, you can simply reorder the parts of your date string to create a compatible ISO 8601 date string which is accepted by the new Date() constructor.

const date_string = "01.01.2022"
const oDate = new Date(date_string.replace(/(.*)\.(.*)\.(.*)/, '$3-$2-$1'))
console.log(oDate.toUTCString())

Leave a Reply

Your email address will not be published. Required fields are marked *