[javascript] 실시간 Date

bunny.log·2023년 5월 17일
0

코드

const [time, setTime] = useState(new Date());

useEffect(() => {
  const id = setInterval(() => {
    setTime(new Date());
  }, 1000);
  return (() => clearInterval(id))
}, []);

return <p>{time.toLocaleString()}</p>

브라우저 화면

링크텍스트

위 링크로 이동해 보면 포멧으로 1초마다 date가 갱신된다.

.
.
.
.
.

관련 좋은글 참고
https://blog.munilive.com/posts/javascript-localization-with-toLocaleString.html

profile
더 많은 유익한 내용은 ->> https://github.com/nam-yeun-hwa

0개의 댓글