(source, length)
| 4 | */ |
| 5 | Date.prototype.format = function (pattern) { |
| 6 | let pad = function (source, length) { |
| 7 | let pre = "", |
| 8 | negative = (source < 0), |
| 9 | string = String(Math.abs(source)); |
| 10 | |
| 11 | if (string.length < length) { |
| 12 | pre = (new Array(length - string.length + 1)).join('0'); |
| 13 | } |
| 14 | |
| 15 | return (negative ? "-" : "") + pre + string; |
| 16 | }; |
| 17 | |
| 18 | if ('string' !== typeof pattern) { |
| 19 | return this.toString(); |