Js timestamp conversion

the string 1542274800000 passed from the background, how to convert it to time format

Nov.19,2021


Date.prototype.Format = function (fmt) {
    var o = {
            "M+": this.getMonth() + 1, // 
            "d+": this.getDate(), // 
            "h+": this.getHours(), // 
            "m+": this.getMinutes(), // 
            "s+": this.getSeconds(), // 
            "q+": Math.floor((this.getMonth() + 3) / 3), // 
            "S": this.getMilliseconds() // 
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + ""));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
new Date(1542274800000).Format('yy-MM-dd hh:mm:ss'); //"2018-11-15 17:40:00"

javascript timestamp changes to date-time custom format, supporting multiple combinations of year, month, week, day, hour, minute and second

< H2 > example < / H2 >
year, month, day, hour, minute, second
  

moment.js
you can change to whatever format you want

Menu