31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
/**
|
|
* 로컬(한국) 시간 기준 날짜/시간 포맷 유틸리티
|
|
* DB 타임존이 Asia/Seoul로 설정되어 있어 로컬 시간 기준으로 포맷
|
|
*
|
|
* toISOString()은 항상 UTC를 반환하므로 자동값 생성 시 사용 금지
|
|
*/
|
|
|
|
export function toLocalDate(date: Date = new Date()): string {
|
|
const y = date.getFullYear();
|
|
const m = String(date.getMonth() + 1).padStart(2, "0");
|
|
const d = String(date.getDate()).padStart(2, "0");
|
|
return `${y}-${m}-${d}`;
|
|
}
|
|
|
|
export function toLocalTime(date: Date = new Date()): string {
|
|
const h = String(date.getHours()).padStart(2, "0");
|
|
const min = String(date.getMinutes()).padStart(2, "0");
|
|
const sec = String(date.getSeconds()).padStart(2, "0");
|
|
return `${h}:${min}:${sec}`;
|
|
}
|
|
|
|
export function toLocalDateTime(date: Date = new Date()): string {
|
|
return `${toLocalDate(date)} ${toLocalTime(date)}`;
|
|
}
|
|
|
|
export function toLocalDateTimeForInput(date: Date = new Date()): string {
|
|
const h = String(date.getHours()).padStart(2, "0");
|
|
const min = String(date.getMinutes()).padStart(2, "0");
|
|
return `${toLocalDate(date)}T${h}:${min}`;
|
|
}
|