본문 바로가기
프로그래밍 언어/JavaScript

[JS] Date를 이용한 날짜 및 요일 구하기

by nahkim 2024. 5. 27.
function get_date() {
    let year = ""
    let month = ""
    let day = ""
    let weekday = ""
    const WEEKDAY = ['일요일', '월요일', '화요일', '수요일', '목요일', '금요일', '토요일']

    let current_date = new Date();

    year = String(current_date.getFullYear());
    month = String(current_date.getMonth() + 1);
    day = String(current_date.getDate());
    weekday = WEEKDAY[current_date.getDay()]
    return year + "년 " + month + "월 " + day + "일" + " " + weekday;
}

 

 

참조 : 

 

[JavaScript][날짜] Date 활용해서 요일 구하기

Date생성자는 시간의 특정 지점을 나타내는 Date 객체를 생성합니다. Date객체는 1970년 1월 1일 UTC(국제표준시) 00:00으로부터 지난 시간을 밀리초로 나타내는 유닉스 타임스탬프를 사용합니다. 날짜

mizzo-dev.tistory.com

 

'프로그래밍 언어 > JavaScript' 카테고리의 다른 글

[JavaScript] numeric separator  (0) 2023.02.01