45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
export default defineNuxtPlugin((/* nuxtApp */) => {
|
|
// _utils.log('defineNuxtPlugin() of customDateTimeFormat.ts executed...');
|
|
return {
|
|
provide: {
|
|
customFormat: (rawtime) => {
|
|
const date: any = new Date(rawtime);
|
|
const year = date.getFullYear();
|
|
const month = date.getMonth() + 1;
|
|
const day = date.getDate();
|
|
let hh = date.getHours();
|
|
const mm = date.getMinutes();
|
|
|
|
const AmOrPm = hh <= 12 ? '오전' : '오후';
|
|
hh = hh % 12 || 12;
|
|
|
|
const diffInSec = Math.floor((Date.now() - date) / 1000);
|
|
if (diffInSec < 30) {
|
|
return '조금 전';
|
|
}
|
|
if (diffInSec < 59) {
|
|
return diffInSec + '초 전';
|
|
}
|
|
const diffInMin = Math.floor(diffInSec / 60);
|
|
if (diffInMin < 59) {
|
|
return diffInMin + '분 전';
|
|
}
|
|
return (
|
|
year +
|
|
'년 ' +
|
|
month +
|
|
'월' +
|
|
' ' +
|
|
day +
|
|
'일, ' +
|
|
AmOrPm +
|
|
' ' +
|
|
hh +
|
|
':' +
|
|
mm
|
|
);
|
|
},
|
|
},
|
|
};
|
|
});
|