js script string dd-MMM-yyyy how change to string 20210127 code example
Example: javascript date to string format dd mmm yyyy
Date.prototype.toShortFormat = function() {
let monthNames =["Jan","Feb","Mar","Apr",
"May","Jun","Jul","Aug",
"Sep", "Oct","Nov","Dec"];
let day = this.getDate();
let monthIndex = this.getMonth();
let monthName = monthNames[monthIndex];
let year = this.getFullYear();
return `${day}-${monthName}-${year}`;
}
let anyDate = new Date(1528578000000);
console.log(anyDate.toShortFormat());