Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- CSS
- API token
- icon
- react env
- API 토큰
- ngrok설치
- github io
- react typescript
- getModifierState
- SCSS
- nextjs
- bootstrap
- npm styled-reset
- react
- There isn’t anything to compare
- dart 변수
- 컨디셔널 렌더링
- rewrites
- nextjs 설치
- github
- fetch
- input type=file
- nextjs .env
- next.js css
- createGlobalStyle
- styled components
- ngrok실행
- Git
- git lab
- typescript react
Archives
- Today
- Total
꾸준히 성장하는 개발자
[JavaScript] 시계 만들기 본문
Date( )
Date object는 내가 이걸 호출하는 당시의 현재 날짜랑 시간을 알려준다.
setInterval( )
setInterval ( 실행하고자하는 함수 , 호출되는 함수의 시간의 간격(ms) )
ex) setInterval(sayHello, 5000); //5초마다
const clock = document.querySelector("h2#clock");
function getClock() {
const date = new Date();
clock.innerText = `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
}
// setInterval(실행하고자하는 함수, 호출되는 함수의 시간의 간격(ms) )
// setInterval(sayHello, 5000); //5초마다
// setTimeout(함수, 얼마나 기다릴지 시간(ms단위)) //5초후에 작동
getClock();
setInterval(getClock, 1000);
padStart(string의 길이, 만약 string의 길이가 못미치면 앞에 들어갈 string)
ex) "1".padStart(2,"0") ------>"01"
만일 뒤에 문자를 넣고 싶다면 padEnd()를 사용하면 된다.
const clock = document.querySelector("h2#clock");
function getClock() {
const date = new Date();
const hours = String(date.getHours()).padStart(2, "0");
const minutes = String(date.getMinutes()).padStart(2, "0");
const seconds = String(date.getSeconds()).padStart(2, "0");
clock.innerText = `${hours}:${minutes}:${seconds}`;
}
// setInterval(실행하고자하는 함수, 호출되는 함수의 시간의 간격(ms) )
// setInterval(sayHello, 5000); //5초마다
// setTimeout(함수, 얼마나 기다릴지 시간(ms단위)) //5초후에 작동
getClock();
setInterval(getClock, 1000);
'JavaScript' 카테고리의 다른 글
[JavsScript] 생성자 함수 (0) | 2022.04.15 |
---|---|
data type (0) | 2022.02.28 |
물음표 연산자 , 삼항연산자 , 조건부 연산자 (0) | 2022.02.27 |
HTMLCollection - > Array로 바꾸기 (0) | 2022.02.23 |
var , let , const (0) | 2021.12.28 |