dukDukz
21.04.15 Calender 달력 본문
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
let setYear = 2021;
let setMonth = 4;
let setDay = 1;
let dt = new Date(`${setYear}-${setMonth}-${setDay}`);
let arrDayStr = ['일', '월', '화', '수', '목', '금', '토'];
let year = dt.getFullYear();
let Month = dt.getMonth() + 1;
let day = dt.getDate();
let MonthTxt = String(Month).padStart(2, 0);
let dayTxt = String(day).padStart(2, 0);
console.log(`${year}년 ${Month}월`);
// 일 월 화 수 목 금 토
let Daytxt = '';
arrDayStr.forEach((v) => {
Daytxt += String(v + " ");
});
console.log(Daytxt);
// 배열
let Dayarr = [];
let Dayarr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
let dt2 = new Date(setYear, setMonth, 0);
let lastDay = dt2.getDate();
let weekDay = dt.getDay();
let newArr = [];
for (i = 0; i < lastDay + weekDay; i++) {
if (i < weekDay) {
Dayarr[i] = " ";
} else {
// 여기서 String 값으로 변경해서 push
Dayarr.push(String(i + 1 - weekDay).padStart(2,0));
if ((i + 1) % 7 == 0) {
newArr.push(Dayarr);
Dayarr = [];
}
}
}
newArr.push(Dayarr);
// console.log(newArr)
// 여기변경
newArr.forEach(v=>{
sum = '';
v.forEach(v2=>{
sum+=v2 + ' '
})
console.log(sum);
})
</script>
</head>
<body>
</body>
</html>
'웹 개발 > JAVASCRIPT' 카테고리의 다른 글
210429 Prototype / __proto__ / Class (0) | 2021.04.29 |
---|---|
객체 Object (0) | 2021.04.26 |
21.04.15 배열. filter, find, map, reduce (0) | 2021.04.15 |
21.04.14 배열과 이중배열 (0) | 2021.04.14 |
210403 여러 슬라이더를 하나의 function으로 동작시키기 (0) | 2021.04.13 |