알고리즘 문제 풀다 현재 날짜 및 시간을 구해봤다
function solution(a, b) {
let aa = new Date() // 현재 일시
let year = aa.getFullYear()
let month = aa.getMonth()+1
let date = aa.getDate()
let dayLabel = aa.getDay()
let hours = aa.getHours()
console.log(year)
console.log(month)
console.log(date)
console.log(dayLabel)
console.log(hours)
return year;
}
month의 경우 1월이 0부터 시작하기 때문에 해당 월을 구할 경우 +1을 해줘야 한다.
1월(0)~12월(11)
요일인 dayLabel의 경우 숫자로 나와서 문자로 바꿔줘야 한다.
출력값은 아래와 같이 나온다.