1Date.prototype.toShortFormat = function() {
2
3 let monthNames =["Jan","Feb","Mar","Apr",
4 "May","Jun","Jul","Aug",
5 "Sep", "Oct","Nov","Dec"];
6
7 let day = this.getDate();
8
9 let monthIndex = this.getMonth();
10 let monthName = monthNames[monthIndex];
11
12 let year = this.getFullYear();
13
14 return `${day}-${monthName}-${year}`;
15}
16
17// Now any Date object can be declared
18let anyDate = new Date(1528578000000);
19
20// and it can represent itself in the custom format defined above.
21console.log(anyDate.toShortFormat());