var originTrim = String.prototype.trim;
String.prototype.trim = function () {
	let args = Array.prototype.slice.call(arguments);
	let str = originTrim.call(this.valueOf())
	if (args.length == 0) return str

	args.forEach(s => {
		if (str.startsWith(s)) {
			str = str.substr(s.length)
		}
		if (str.endsWith(s)) {
			str = str.substr(0, str.length - s.length)
		}
	})
	return str;
}

Date.prototype.Format = function (format) {
    var formatstr = format;
    var format2BitNum = (v) => `${+v + 100}`.slice(1)
    var formatMap = [
        { f: 'yyyy', fn: 'getFullYear' },
        { f: 'yy', fn: 'getFullYear', cb: (y) => y.toString().substr(2) },
        { f: 'MM', fn: 'getMonth', cb: (m) => format2BitNum(m + 1) },
        { f: 'M', fn: 'getMonth', cb: (m) => m + 1 },
        { f: 'dd', fn: 'getDate', cb: format2BitNum },
        { f: 'd', fn: 'getDate' },
        { f: 'HH', fn: 'getHours', cb: format2BitNum },
        { f: 'H', fn: 'getHours', },
        { f: 'hh', fn: 'getHours', cb: (h) => h > 12 ? h - 12 : h },
        { f: 'mm', fn: 'getMinutes', cb: format2BitNum },
        { f: 'm', fn: 'getMinutes', },
        { f: 'ss', fn: 'getSeconds', cb: format2BitNum },
        { f: 's', fn: 'getSeconds', },
        { f: 'fff', fn: 'getMilliseconds' },
    ]
    var self = this;
    if (format != null && format != "") {
        while (formatMap.length > 0) {
            var { f, fn, cb } = formatMap.shift();
            if (formatstr.indexOf(f) != -1) {
                var v = self[fn].call(this);
                if (cb !== undefined) v = cb(v);
                var reg = new RegExp(f, 'g');
                formatstr = formatstr.replace(reg, v);
            }
        }
    }
    return formatstr;
}

Number.prototype.Format = function (format) {
    return new Date(this).Format(format);
}
