SOURCE


Date.prototype.format = function(format) {
    var f = {
        "M+" : this.getMonth() + 1,
        "d+" : this.getDate(),
        "h+" : this.getHours(),
        "m+" : this.getMinutes(),
        "s+" : this.getSeconds(),
    };

    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, this.getFullYear() + "");
    }

    for (var k in f) {
        if (new RegExp('('+ k +')').test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? f[k] : ('00' + f[k]).substr(('' + f[k]).length));
        }
    }

    return format;
}
let a = new Date("5/23/2019 15:30:29")
let b=  a.format('yyyy-MM-dd-hh:mm:ss');
console.log(b)
console 命令行工具 X clear

                    
>
console