Date
new Date()
- 현재 시각
- '요일명 월 일 년도 시:분:초 GMT기준시간' 표시
Get날짜함수
getFullYear()
getMonth()
- 월 : MM
- 주의
=> 자바스크립트의 월은 0부터 시작하기 때문에 1을 더해야 정상적인 월이 표시된다.
getDate()
getDay()
getHours()
getMinutes()
getSeconds()
getMilliseconds()
Set날짜함수의 종류
- setFullYear() / setMonth() / setDate() / setHours() / setMinutes() / setSeconds() / setMilliseconds()
현재 시간을 알려주는 함수
function func_currentDate(){
const now = new Date();
console.log(now);
console.log(now.toLocaleString());
const year = now.getFullYear();
let month = now.getMonth() + 1;
let date = now.getDate();
if(month < 10){
month = "0" + month;
}
if(date < 10){
date = "0" + date;
}
let hours = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
if(hours < 10){
hours = "0" + hours;
}
if(minutes < 10){
minutes = "0" + minutes;
}
if(seconds < 10){
seconds = "0" + seconds;
}
const day = now.getDat();
let dayName;
switch(day){
case 0:
dayName = "일요일"
break;
case 1:
dayName = "월요일"
break;
case 2:
dayName = "화요일"
break;
case 3:
dayName = "수요일"
break;
case 4:
dayName = "목요일"
break;
case 5:
dayName = "금요일"
break;
case 6:
dayName = "토요일"
break;
}
return `${year}-${month}-${date}
${hours}:${minutes}:${seconds} ${dayName}`;
}
정리
- 09javascriptStandardObject
-> 02_Date -> 01현재날짜시간_시계만들기.html, 01.css, 01.js