😎풀이

  1. date에서 공백 기준으로 , , 분리
  2. 일자는 th를 제거하고 한자리 수 인 경우 앞에 0을 붙여 09와 같이 표시되도록 설정
  3. 월은 사전 정의된 달에 1-Indexed를 적용하며, 10월 이전인 경우 0을 붙여 09와 같이 푶시되도록 설정
  4. 하이픈(-)을 통해 , , 을 연결하여 반환환
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}`
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글