설치

npm install dayjs

타임존 설정 + 타임스탬프 출력 예제

import dayjs, { Dayjs } from "dayjs";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";

export class DatetimeUtil {
    public static getCurrentTime() {
        const cur = dayjs().tz("Asia/Seoul");
        const curDate = cur.format("YYYY-MM-DD");
        const curTime = cur.format("HH:mm:ss");
        return `[${curDate}] ${curTime}`;
    }
}

// Globally
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.tz.setDefault("Asia/Seoul"); // Not Work
dayjs.locale("ko");