You could extract the date parts and build the date string manually, like so:
const mydate = "25/05/2023 2:30 PM";
console.log( dateFormatter(mydate) );
function dateFormatter(datestr){
const regex = /^(\d{2})\/(\d{2})\/(\d{4}) (\d{1,2}):(\d{2}) ([AP]M)$/;
const match = datestr.match(regex);
if( ! match )
throw new Error('Invalid date format')
// pull out the date parts
const parts = match.slice(1);
let day = parts[0];
let month = parts[1];
let year = parts[2];
let hours = parseInt(parts[3], 10); // must be int to add 12 for 24H
let minutes = parts[4];
// change 12H to 24H
hours += (parts[5] == 'PM' ? 12 : 0);
// pad hours to two digits
hours = ('00'+hours).substr(-2);
// format any way you like:
return `${year}-${month}-${day}T${hours}:${minutes}`;
}
Javascript sadly does not support the /x flag or custom delimiters in regexes, like Perl does. So the regex is a little crammed and suffers from leaning toothpicks.
Otherwise, it is pretty straight forward.