MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / dayFormat

Function dayFormat

src/pkg/utils/day_format.ts:20–50  ·  view source on GitHub ↗
(date = new Date(), fmt = "YYYY-MM-DD HH:mm:ss")

Source from the content-addressed store, hash-verified

18const formatRe = /YYYY|MM|DD|HH|mm|ss/g;
19
20export 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}

Callers 6

onWatchFileCodeChangedFunction · 0.90
onScriptUpdateCheckFunction · 0.90
logMethod · 0.90
requestExportMethod · 0.90
backupToCloudMethod · 0.90
formatUnixTimeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected