ucharles / gachatory

https://www.gachatory.com
0 stars 0 forks source link

fix: `Intl.DateTimeFormat()`의 00시가 24시로 표기되는 것을 수정 #96

Closed ucharles closed 7 months ago

ucharles commented 7 months ago

함수 내용

export function convertToLocalTime(isoDateString: string): string {
  // ISO 형식의 문자열을 Date 객체로 변환
  const date = new Date(isoDateString);

  // Intl.DateTimeFormat을 사용하여 사용자의 로컬 시간대에 맞는 날짜와 시간을 포맷
  const dateTimeFormatOptions: Intl.DateTimeFormatOptions = {
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
    hour: "2-digit",
    minute: "2-digit",
    second: "2-digit",
    hourCycle: "h23", // 24시간 형식을 사용하려면 이 옵션을 설정
  };

  // 로컬 시간대로 변환된 날짜와 시간 문자열 반환
  return Intl.DateTimeFormat("default", dateTimeFormatOptions).format(date);
}

수정 내용

ucharles commented 7 months ago

https://github.com/ucharles/gachatory/pull/94 에서 반영 완료