/** * 날짜/시간 포맷 유틸 — KST(Asia/Seoul) 고정 출력. * * 서버에서 UTC ISO 문자열이 오든, Date 객체가 오든 * 항상 KST로 변환하여 표시합니다. */ const KST: Intl.DateTimeFormatOptions = { timeZone: 'Asia/Seoul' }; /** 2026-04-07 14:30:00 형식 (KST). sv-SE 로케일은 ISO 유사 출력을 보장. */ export const formatDateTime = (value: string | Date | null | undefined): string => { if (!value) return '-'; const d = typeof value === 'string' ? new Date(value) : value; if (isNaN(d.getTime())) return '-'; return d.toLocaleString('sv-SE', { ...KST, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false, }); }; /** 2026-04-07 형식 (KST) */ export const formatDate = (value: string | Date | null | undefined): string => { if (!value) return '-'; const d = typeof value === 'string' ? new Date(value) : value; if (isNaN(d.getTime())) return '-'; return d.toLocaleDateString('sv-SE', { ...KST, year: 'numeric', month: '2-digit', day: '2-digit', }); }; /** 14:30:00 형식 (KST) */ export const formatTime = (value: string | Date | null | undefined): string => { if (!value) return '-'; const d = typeof value === 'string' ? new Date(value) : value; if (isNaN(d.getTime())) return '-'; return d.toLocaleTimeString('sv-SE', { ...KST, hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false, }); }; /** yyyy-MM-dd 형식 문자열 (KST 기준, API 파라미터용) */ export const toDateParam = (d: Date = new Date()): string => { const kst = new Date(d.toLocaleString('en-US', KST)); const y = kst.getFullYear(); const m = String(kst.getMonth() + 1).padStart(2, '0'); const day = String(kst.getDate()).padStart(2, '0'); return `${y}-${m}-${day}`; };