[JS] Date - padStart(2,'0')

민갱·2023년 9월 20일
0

JS

목록 보기
2/2
  • month는 +1을 해줘야한다.
  • 두자리 수 채워서 월,일 을 만들고 싶으면 padStart 사용.
const getMayDate = (createDate)=>{
  const data = new Date(createDate)
  const yyyy = date.getFullYear()
  const mm = String(date.getMonth()+1).padStart(2,'0')
  const dd = String(date.getDate()).padStart(2,'0')
  return `${yyyy}-${mm}-${dd}`
}

return(
  <div>
	  <p>{getMayDate(date)}</p>
  </div>
)
profile
가보자고

0개의 댓글