프론트엔드/JavaScript

자바스크립트 날짜와 시간

윷땡 2022. 4. 27. 20:46

2022.04.27

Javascript Date

const date = new Date()
console.log(date.getFullYear())
console.log(date.getMonth()) // +1
console.log(date.getDate()) 
console.log(date.getHours()) 
console.log(date.getMinutes()) 
console.log(date.getSeconds())

// 날짜출력방법
const res = `${year}.${month}.${day}`; //년.원.일 변수 res로
const today = document.querySelector('.date'); //data클래스
today.textContent = res;