|
@@ -1,20 +1,20 @@
|
|
|
export function format(format: string, time?: number) {
|
|
export function format(format: string, time?: number) {
|
|
|
- const now = time ? new Date(time) : new Date()
|
|
|
|
|
|
|
+ const now = time ? new Date(time) : new Date();
|
|
|
const map: Record<string, string | number> = {
|
|
const map: Record<string, string | number> = {
|
|
|
y: now.getFullYear(),
|
|
y: now.getFullYear(),
|
|
|
- M: now.getMonth() + 1,
|
|
|
|
|
- d: now.getDate(),
|
|
|
|
|
|
|
+ M: now.getMonth() + 1 > 9 ? now.getMonth() + 1 : `0${now.getMonth() + 1}`,
|
|
|
|
|
+ d: now.getDate() > 9 ? now.getDate() : `0${now.getDate()}`,
|
|
|
h: now.getHours() > 9 ? now.getHours() : `0${now.getHours()}`,
|
|
h: now.getHours() > 9 ? now.getHours() : `0${now.getHours()}`,
|
|
|
m: now.getMinutes() > 9 ? now.getMinutes() : `0${now.getMinutes()}`,
|
|
m: now.getMinutes() > 9 ? now.getMinutes() : `0${now.getMinutes()}`,
|
|
|
- s: now.getSeconds() > 9 ? now.getSeconds() : `0${now.getSeconds()}`
|
|
|
|
|
- }
|
|
|
|
|
- const res = []
|
|
|
|
|
|
|
+ s: now.getSeconds() > 9 ? now.getSeconds() : `0${now.getSeconds()}`,
|
|
|
|
|
+ };
|
|
|
|
|
+ const res = [];
|
|
|
for (let i = 0; i < format.length; i++) {
|
|
for (let i = 0; i < format.length; i++) {
|
|
|
if (map[format.charAt(i)]) {
|
|
if (map[format.charAt(i)]) {
|
|
|
- res.push(map[format.charAt(i)])
|
|
|
|
|
|
|
+ res.push(map[format.charAt(i)]);
|
|
|
} else {
|
|
} else {
|
|
|
- res.push(format.charAt(i))
|
|
|
|
|
|
|
+ res.push(format.charAt(i));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return res.join('')
|
|
|
|
|
|
|
+ return res.join("");
|
|
|
}
|
|
}
|