Day 8 "setInterval"

Hector·2023년 3월 24일
0

Vanilla JavaScript

목록 보기
8/14
<script>
// setInterval(() => {
//    document.getElementById('time').innerText = new Date();
// },1000);
setInterval(()=>{
    let date = new Date();
    let year = date.getFullYear();
    let month = date.getMonth()+1;
    let day = date.getDate();
    let hours = date.getHours();
    let minutes = date.getMinutes();
    let seconds = date.getSeconds();

    let yoil = date.getDay();
    let han_yoil = '';

    switch(yoil){
        case 0 :
            han_yoil='sunday'
            break;
        case 1 :
            han_yoil='monday'
            break;
        case 2 :
            han_yoil='tuesday'
            break;
        case 3 :
            han_yoil='wednesday'
            break;
        case 4 :
            han_yoil='thursday'
            break;
        case 5 :
            han_yoil='friday'
            break;
        case 6 :
            han_yoil='saturday'
            break;
    }
    let time = document.getElementById('time');
    let time2 = document.getElementById('time2');
    let content = `${year}${month}${day}일(${han_yoil})${hours}시간${minutes}${seconds}`
    
    // HTML tags are applied to web pages only as strings.
    // (문자열로만 HTML태그가 웹페이지에 적용된다.)
        time.innerHTML = `<h1>${content}</h1>`
    // The contents of the string are applied to the homepage as it is.
    // (문자열로된 내용이 그대로 홈페이지에 적용된다.)
        time2.innerText = `<h1>${content}</h1>`

    // Dynamically generate HTML elements(HTML요소를 동적으로 생성)
    let nowElement = document.createElement('h1')
    
    // Add attribute to element(요소에 속성 추가)
    nowElement.setAttribute('id','bigTime');
    
    // 
    nowElement.textContent = content;

    time2.appendChild(nowElement);
    let nowElementId = time2.getAttribute('id')
    console.log(nowElementId);
    
},1000)
</script>
profile
I`m Studying Bankend

0개의 댓글