MCPcopy Create free account
hub / github.com/OpenSIST/OpenSIST.github.io / utcToLocal

Function utcToLocal

src/Data/Common.js:97–113  ·  view source on GitHub ↗
(dateString, dateOnly = false)

Source from the content-addressed store, hash-verified

95 * @returns {string} - Formatted local date string
96 */
97export function utcToLocal(dateString, dateOnly = false) {
98 const utcString = dateString.replace(" ", "T") + "Z";
99 const date = new Date(utcString);
100
101 const pad = (n) => String(n).padStart(2, "0");
102
103 const year = date.getFullYear();
104 const month = pad(date.getMonth() + 1);
105 const day = pad(date.getDate());
106 const hours = pad(date.getHours());
107 const minutes = pad(date.getMinutes());
108 const seconds = pad(date.getSeconds());
109
110 return dateOnly
111 ? `${year}-${month}-${day}`
112 : `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
113}

Callers 2

PostContentFunction · 0.90
CommentItemFunction · 0.90

Calls 1

padFunction · 0.85

Tested by

no test coverage detected