상세 컨텐츠

본문 제목

[ JavaScript ] 오늘 날짜 출력하기

FrontEnd/JavaScript

by SangHoonE 2021. 11. 22. 14:33

본문

반응형

다양한 오늘날짜를 출력하는 방법 중에서

20211122포맷을 출력하는 방법

함수로 선언하기

function getTodayDate () {
            const todayDate = new Date()
            const year = todayDate.getFullYear()
            const months = todayDate.getMonth()+1
            const days = todayDate.getDate()
            const resultDate = year + '' + months + '' + days
            return resultDate
        }

// resultDate의 값이 반환됩니다.
getTodayDate()

 

그냥 선언하기

const todayDate = new Date()
const year = todayDate.getFullYear()
const months = todayDate.getMonth()+1
const days = todayDate.getDate()
const resultDate = year + '' + months + '' + days

//아래 결과 : 20211122
console.log(resultDate)

 

관련글 더보기

댓글 영역