시계를 만들어봄, setInterval은 나중에 ㅋ
function timeAMPM(){
const today = new Date().getHours
if (today < 12){
AMPM.textContent = 'am'
} else {
AMPM.textContent = 'pm'
}
}
timeAMPM()
function getTime(){
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.textContent = (`${hours} : ${minutes} : ${second}`)
}
getTime()
setInterval(getTime, 1000)
// getTime함수를 1초마다 실행시킨다
Date.prototype.getHours()
Date에서 현지 시간 기준 시(0–23)를 반환합니다
Date.prototype.getHours() - JavaScript | MDN
getHours() 메서드는 주어진 날짜의 현지 시간 기준 시를 반환합니다.
developer.mozilla.org
Date.prototype.getMinutes()
Date에서 현지 시간 기준 분(0–59)을 반환합니다
Date.prototype.getMinutes() - JavaScript | MDN
getMinutes() 메서드는 Date 인스턴스의 분을 현지 시간 기준으로 반환합니다.
developer.mozilla.org
Date.prototype.getMonth()
Date에서 현지 시간 기준 월(0–11)을 반환합니다
Date.prototype.getMonth() - JavaScript | MDN
getMonth() 메서드는 Date 객체의 월 값을 현지 시간에 맞춰 반환합니다. 월은 0부터 시작합니다.
developer.mozilla.org
Date.prototype.getSeconds()
Date에서 현지 시간 기준 초(0–59)를 반환합니다
Date.prototype.getSeconds() - JavaScript | MDN
getSeconds() 메서드는 Date 객체의 초 값을 현지 시간에 맞춰 반환합니다.
developer.mozilla.org
'개발공부_Blog > JavaScript' 카테고리의 다른 글
isNaN() - NaN인지 판별하는 함수 (0) | 2022.01.18 |
---|---|
javascript _ Date() 밀리초를 날짜로 변환하기 (0) | 2022.01.18 |
Date객체 1 - 연도, 월, 일, 요일 (0) | 2022.01.15 |
String.prototype.slice() 문자열의 일부를 새로운 문자열로 반환 (0) | 2022.01.15 |
Array.prototype.slice() 배열에서 시작과 끝을 추출하는 함수 (0) | 2022.01.15 |
댓글