📌  相关文章
📜  javascript 日期到字符串格式 dd mmm yyyy - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:23.853000             🧑  作者: Mango

代码示例1
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}`;  
}

// Now any Date object can be declared 
let anyDate = new Date(1528578000000);

// and it can represent itself in the custom format defined above.
console.log(anyDate.toShortFormat());