01. 날짜 불러오기

번호 기본값 메서드 결과값
{
    const date = new Date();

    const year = date.getFullYear();
    document.querySelector(".sample01_R1").innerHTML = "지금은 " + year + "년 입니다.";

    const month = date.getMonth() + 1;
    document.querySelector(".sample01_R2").innerHTML = "지금은 " + month + "월 입니다.";

    const day = date.getDate();
    document.querySelector(".sample01_R3").innerHTML = "지금은 " + day + "일 입니다.";

    const hour = date.getHours();
    document.querySelector(".sample01_R4").innerHTML = "지금은 " + hour + "시 입니다.";

    const minutes = date.getMinutes();
    document.querySelector(".sample01_R5").innerHTML = "지금은 " + minutes + "분 입니다.";

    const seconds = date.getSeconds();
    document.querySelector(".sample01_R6").innerHTML = "지금은 " + seconds + "초 입니다.";

    const milliseconds = date.getMilliseconds();
    document.querySelector(".sample01_R7").innerHTML = "지금은 " + milliseconds + "초 입니다.";

    const day = date.getDay();
    const dayList = ['일요일', '월요일', '화요일', '수요일', '목요일', '금요일', '토요일'];
    document.querySelector(".sample01_R8").innerHTML = "지금은 " + dayList[day] + " 입니다.";
}

02. 날짜 불러오기

번호 기본값 메서드 결과값
{
    const date = new Date();
    const locale = date.toLocaleString();
    const localeData = date.toLocaleDateString();
    const localeTime = date.toLocaleTimeString();

    document.querySelector(".sample02_R1").innerHTML = locale;
    document.querySelector(".sample02_R2").innerHTML = localeData;
    document.querySelector(".sample02_R3").innerHTML = localeTime;    
}

03. 날짜 메서드 : Date.parse() : 날짜 문자열 타임스탬프 불러오기

번호 기본값 메서드 결과값
{
    const date = Date.parse("2021/08/11");

    document.querySelector(".sample03_N1").innerHTML = "1";
    document.querySelector(".sample03_Q1").innerHTML = "2021/08/11";
    document.querySelector(".sample03_M1").innerHTML = "Date.parse()";
    document.querySelector(".sample03_R1").innerHTML = date;

    const date2 = Date.parse("8 11 2021");

    document.querySelector(".sample03_N2").innerHTML = "2";
    document.querySelector(".sample03_Q2").innerHTML = "8 11 2021";
    document.querySelector(".sample03_M2").innerHTML = "Date.parse()";
    document.querySelector(".sample03_R2").innerHTML = date2;

    const date3 = Date.now();

    document.querySelector(".sample03_N3").innerHTML = "3";
    document.querySelector(".sample03_Q3").innerHTML = "";
    document.querySelector(".sample03_M3").innerHTML = "Date.now()";
    document.querySelector(".sample03_R3").innerHTML = date3;
}