i have a variable value that is giving me the data as "Session between Jan 15 2022 4:00Am And Jan 15 2022 4:30Am", i want to format this date string into "Session between 15-01-2022 4:00Am And 15-01-2022 4:30Am".
Things i have tried:
//function to remove "session between and" so that the date can be parsed.
public removeUnwantedText(words : any){
var cleanUpWords = ["Session","between","And"];
var expStr = cleanUpWords.join("\\b|\\b");
return words.replace(new RegExp(expStr, 'gi'), '').trim().replace(/ +/g, ' ');
}
//calling the function and trying to format date string,where value="Session between Jan 15 2022 4:00Am And Jan 15 2022 4:30Am"
console.log(moment( this.removeUnwantedText(value),"MMM DD YYYY h:mmA").format('[Session between] DD-MM-YYYY h:mmA [And] DD-MM-YYYY h:mmA'));
the console ouptut is : Session between 01/15/2022 4:00Am And 01/15/2022 4:00Am
but the required output is Session between 01/15/2022 4:00Am And 01/15/2022 4:30Am
Any kind of help and suggestions would be appreciated. Thanks in advance