JS padstart

Heewon👩🏻‍💻·2024년 4월 26일

padStart : String에 쓰는도구, 일정한 글자 크기를 만들기 위함이다.

"1"이란 숫자를 "01"처럼 2글자로 만들고 싶을때 쓰는 도구!
ex) "1".padStart(2,"0") ➞ "01"

  const date = new Date();
  const Hours = String(date.getHours()).padStart(2, "0");
  const Minutes = String(date.getMinutes()).padStart(2, "0");
  const Second = String(date.getSeconds()).padStart(2, "0");

  clock.innerText = `${Hours}:${Minutes}:${Second}`;

Date 에 출력되는 시간은 숫자라서 문자로 변환시켜줘야함.
시계 만들때 1초를 01초로 보여주게 하기위해서 padStart(원하는글자길이, 추가해야할글자) 사용!

profile
Interested in coding, meat lover, in love with dogs , enjoying everything happens in my life.

0개의 댓글