
😎풀이
date
에서 공백 기준으로 일
, 월
, 년
분리
- 일자는
th
를 제거하고 한자리 수 인 경우 앞에 0
을 붙여 09
와 같이 표시되도록 설정
- 월은 사전 정의된 달에
1-Indexed
를 적용하며, 10월 이전인 경우 0
을 붙여 09
와 같이 푶시되도록 설정
- 하이픈(
-
)을 통해 년
, 월
, 일
을 연결하여 반환환
function reformatDate(date: string): string {
const monthWord = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
const [day, month, year] = date.split(' ')
const realDay = day.replaceAll(/[a-zA-Z]/gi, '').padStart(2, '0')
const realMonth = String(monthWord.indexOf(month) + 1).padStart(2, '0')
return `${year}-${realMonth}-${realDay}`
};