300x250
자바스크립트로 현재 시간을 출력하는 방법 중 가장 일반적인 방법인 Date 객체를 사용하는 것 말고
지역 설정에 맞는 시간 형식으로 현재 시간을 출력할 수 있습니다.

아래가 그 결과입니다.
자세한 설명은 이곳에
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
Intl.DateTimeFormat - JavaScript | MDN
Intl.DateTimeFormat 은 언어에 맞는 날짜 및 시간 서식을 적용하기 위한 객체입니다.
developer.mozilla.org
아래는 전체 코드입니다.
const KoreanFormatter = new Intl.DateTimeFormat('ko-KR', {
//numeric: 숫자형식 / long: 전체 이름 / narrow: 가장 짧은 형식
year: 'numeric',
month: 'long',
day: 'numeric',
weekday: 'narrow',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
});
setInterval(() => {
const nowTime = KoreanFormatter.format(new Date());
document.body.innerText = '';
document.body.innerText = nowTime;
}, 1000);
(광고 클릭은 제작에 큰 힘이 됩니다.)
300x250
'HTML CSS JAVASCRIPT' 카테고리의 다른 글
자바스크립트 클릭하면 폭죽 터지는 UI (그냥 만들어봄) (0) | 2025.02.28 |
---|---|
자바스크립트로 차르르 올라가는 숫자 표현하기 (오도미터 카운터) (0) | 2025.02.27 |
자바스크립트 mousedown / touchstart 를 한번에 처리 (0) | 2025.02.25 |
자바스크립트로 게임 만들기 (슬라이딩 퍼즐) (0) | 2025.02.24 |
CSS Transition 종료 후 다른 기능 실행 (자바스크립트) (2) | 2025.02.19 |