(date = new Date(), fmt = "YYYY-MM-DD HH:mm:ss")
| 18 | const formatRe = /YYYY|MM|DD|HH|mm|ss/g; |
| 19 | |
| 20 | export function dayFormat(date = new Date(), fmt = "YYYY-MM-DD HH:mm:ss"): string { |
| 21 | return fmt.replace(formatRe, (token) => { |
| 22 | switch (token) { |
| 23 | case "YYYY": { |
| 24 | const y = date.getFullYear(); |
| 25 | return y.toString(); |
| 26 | } |
| 27 | case "MM": { |
| 28 | const m = date.getMonth() + 1; |
| 29 | return m < 10 ? "0" + m : m.toString(); |
| 30 | } |
| 31 | case "DD": { |
| 32 | const d = date.getDate(); |
| 33 | return d < 10 ? "0" + d : d.toString(); |
| 34 | } |
| 35 | case "HH": { |
| 36 | const h = date.getHours(); |
| 37 | return h < 10 ? "0" + h : h.toString(); |
| 38 | } |
| 39 | case "mm": { |
| 40 | const min = date.getMinutes(); |
| 41 | return min < 10 ? "0" + min : min.toString(); |
| 42 | } |
| 43 | case "ss": { |
| 44 | const s = date.getSeconds(); |
| 45 | return s < 10 ? "0" + s : s.toString(); |
| 46 | } |
| 47 | } |
| 48 | return token; |
| 49 | }); |
| 50 | } |
no outgoing calls
no test coverage detected