I need to get the date format as \'DD-Mon-YYYY\' in javascript. I had asked a question, and it got marked duplicate to jQuery date formatting
But, the answers provi
Here's a simple solution, using TypeScript:
convertDateStringToDate(dateStr) {
// Convert a string like '2020-10-04T00:00:00' into '4/Oct/2020'
let months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
let date = new Date(dateStr);
let str = date.getDate()
+ '/' + months[date.getMonth()]
+ '/' + date.getFullYear()
return str;
}
(Yeah, I know the question was about JavaScript, but I'm sure I won't be the only Angular developer coming across this article !)