function dateFormat(format) {
const weekName = ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"];
const d = new Date();
const lpad = x => String(x).padStart(2, '0');
return format.replace(/(yyyy|yy|mm|dd|e|24h|hh|mi|ss|a\/p)/gi, function($1) {
switch ($1) {
case "yyyy": return d.getFullYear();
case "yy": return lpad(d.getFullYear() % 1000);
case "mm": return lpad(d.getMonth() + 1);
case "dd": return lpad(d.getDate());
case "e": return weekName[d.getDay()];
case "24h": return lpad(d.getHours());
case "hh": return lpad(d.getHours() % 12 ? d.getHours() % 12 : 12);
case "mi": return lpad(d.getMinutes());
case "ss": return lpad(d.getSeconds());
case "a/p": return d.getHours() < 12 ? "오전" : "오후";
default: return $1;
}
});
}
dateFormat('yyyy-mm-dd 24h:mi:ss a/p');
// '2022-06-21 16:06:59 오후'