공통 날짜 포멧팅 함수 추가
This commit is contained in:
parent
5f80998da8
commit
84c43d5baf
@ -38,12 +38,46 @@ const common = {
|
|||||||
}
|
}
|
||||||
console.error('잘못된 Delta 객체:', content);
|
console.error('잘못된 Delta 객체:', content);
|
||||||
return null; // Delta 객체가 아니거나 ops가 없을 경우 null 반환
|
return null; // Delta 객체가 아니거나 ops가 없을 경우 null 반환
|
||||||
}
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date 타입 문자열 포멧팅
|
||||||
|
*
|
||||||
|
* @param {string} dateStr
|
||||||
|
* @return
|
||||||
|
* 1. Date type 인 경우 예시 '25-02-24 12:02'
|
||||||
|
* 2. Date type 이 아닌 경우 입력값 리턴
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
dateFormatter(dateStr) {
|
||||||
|
const date = new Date(dateStr);
|
||||||
|
const dateCheck = date.getTime();
|
||||||
|
|
||||||
|
if (isNaN(dateCheck)) {
|
||||||
|
return dateStr;
|
||||||
|
} else {
|
||||||
|
const { year, month, day, hours, minutes } = this.formatDateTime(date);
|
||||||
|
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
formatDateTime(date) {
|
||||||
|
const zeroFormat = num => (num < 10 ? `0${num}` : num);
|
||||||
|
|
||||||
|
return {
|
||||||
|
year: date.getFullYear(),
|
||||||
|
month: zeroFormat(date.getMonth() + 1),
|
||||||
|
day: zeroFormat(date.getDate()),
|
||||||
|
hours: zeroFormat(date.getHours()),
|
||||||
|
minutes: zeroFormat(date.getMinutes()),
|
||||||
|
seconds: zeroFormat(date.getSeconds()),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
install(app) {
|
install(app) {
|
||||||
app.config.globalProperties.$common = common;
|
app.config.globalProperties.$common = common;
|
||||||
}
|
app.provide('common', common);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user