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 |
Tags
- NSPredicates
- Persistent store Coordinator
- 2022 부스트캠프
- NSManagedObject SubClass
- NSSortDescriptor
- Associated Value
- 일급 객체
- Swift 고차함수
- 다익스트라 이해
- CoreData Concurrency
- codability
- Raw value and Associated value
- Swift
- CoreData Stack
- 스위프트 클로저
- expensive operation
- iOS Static Library
- dateFormatter
- 트레일링 클로저
- Clean swift
- iOS Static Library 사용하는방법
- CoreData Filter
- Swift closure
- 1009번
- Swift LinkedList
- LightWeight Migration
- CoreData
- leetcode #01
- persistentStoreCoordinator
- Java
Archives
- Today
- Total
하루를살자
JS Clone Project [Clock] - 2, PadStart 본문
To fix the problem at the first version of the clock, we have to consider the time String to always have two characters. To make "1" -> "01"
PadStart --> it is used to String, to display in a "N digit form" of the user desire.
Ex) "1".padStart(2,"0") --> "01"
*The first argument is the "2 digit form" that the user desires to represent the "1" string as.
*The second argument fills the rest of the character from the beginning of the character that is required to satisfy the user's first argument. --> Giving "Padding"
const clock = document.querySelector("#clock");
function getTime () {
//Call for Date object
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.innerHTML = `${hours} : ${minutes} : ${seconds}`;
}
//As soon as the web is loaded, it calls for getTime ();
getTime ();
//setInterval --> Repeat calling sayHi() after 5 seconds since it's loaded
setInterval(getTime, 1000);
//setTimeout --> It gives 5s timeout once the page is loaded and runs the function once
//setTimeout(sayHi, 5000);
*Key Points
1. .padStart()
2. Calling getTime(), first to display time as soon as the page is loaded
3. Use of setInternval.
'JS' 카테고리의 다른 글
JS Clone Project [Background] (0) | 2021.12.05 |
---|---|
JS Clone Project [Quotes] (0) | 2021.12.05 |
JS Clone Project [Clock] - 1 (0) | 2021.12.04 |
JS Clone Project [Login] - 3, Saving User Input (0) | 2021.12.04 |
JS Clone Project [Login] - 2, Getting User Input (0) | 2021.12.04 |
Comments