[JavaScript]getDateStrByFormat

getDateStrByFormat(format,d,defaultValue){
    if(typeof d == 'string'){
        d = this.getDateByYYYYMMDD(d);
    }
    if(!d){
        if(defaultValue != undefined && defaultValue != null){
            return defaultValue;
        }else{
            d = new Date();
        }
    }
    if(!format){
        format = 'Y-m-d';
    }
    const _pz = function(v,digits){
        var vs = v.toString();
        while(vs.length < digits){
            vs = '0' + vs;
        }
        return vs;
    };
    return format
        .replace(/Y/g,d.getFullYear())
        .replace(/y/g,d.getFullYear().toString().substr(2,2))
        .replace(/n/g,d.getMonth()+1)
        .replace(/m/g,_pz(d.getMonth()+1,2))
        .replace(/j/g,d.getDate())
        .replace(/d/g,_pz(d.getDate(),2))
        .replace(/G/g,d.getHours())
        .replace(/H/g,_pz(d.getHours(),2))
        .replace(/i/g,_pz(d.getMinutes(),2))
        .replace(/s/g,_pz(d.getSeconds(),2))
        .replace(/J/g,['日','月','火','水','木','金','土'][d.getDay()])
        .replace(/D/g,['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][d.getDay()]);
}