0928_Javascript : 내장객체 - Date

0928_Javascript : 내장객체 - Date

Insert title here * { margin: 0; padding: 0; box-sizing: border-box; } body { font-size: 14px; font-family: '맑은 고딕', 나눔고딕, 돋움, sans-serif; } #calendarLayout { width: 280px; margin: 30px auto; } #calendarLayout .subject { height: 37px; line-height: 37px; text-align: center; font-weight: 600; } #calendarLayout table { width: 100%; border-collapse: collapse; border-spacing: 0; } #calendarLayout table td { padding: 10px; text-align: center; border: 1px solid #ccc; } #calendarLayout table td:nth-child(7n+1) { color: red; } #calendarLayout table td:nth-child(7n) { color: blue; } #calendarLayout table td.gray { color: #ccc; } #calendarLayout table td.today { background: #e6ffff; } .subject>span, .footer>span { cursor: pointer; } .subject>span:hover, .footer>span:hover { color: tomato; } .footer { height: 25px; line-height: 25px; text-align: right; font-size: 12px; padding-right: 3px; } function calendar(y, m) { var date = new Date(y, m-1, 1); y = date.getFullYear(); m = date.getMonth()+1; var w = date.getDay(); // 요일:0~6 var week = ["일","월","화","수","목","금","토"]; // 배열 // 시스템 오늘 날짜 var now = new Date(); var ny = now.getFullYear(); var nm = now.getMonth()+1; var nd = now.getDate(); var out = "

"; out+= "< "; out+= ""; out+=" >"; out+="
"; out+=""; out+=""; for(var i=0; i"; } out+=""; // 1일 앞부분 : 이전달 var preDate = new Date(y, m-1, 0); // 이전달의 마지막 날짜로 Date 객체 생성 // var preYear = preDate.getFullYear(); // var preMonth = preDate.getMonth()+1; var preLastDay = preDate.getDate(); var preDay = preLastDay - w + 1; out+=""; for(var i =0; i"; // ++preday도 가능 } // 2021년 10월의 마지막 일자는 ? (new Date(2021, 10, 0)).getDate(); 11월 0일(10월 31일) var lastDay = (new Date(y, m, 0)).getDate(); var cls; for(var i=1; i<=lastDay; i++) { cls = ""; if(y=ny&&m==nm&&i==nd) cls =" today "; out +=""; if(i != lastDay && ++w%7==0) { out+=""; } } // 마지막 날짜 부분 var nextDay = 0; for(var i=w%7; i<6; i++) { out+=""; } out+=""; out+="
"+i+"
"+ (++nextDay) +"
"; out+=""; document.getElementById("calendarLayout").innerHTML = out; } window.onload = function(){ var now = new Date(); var y = now.getFullYear(); var m = now.getMonth()+1; calendar(y, m); }

from http://development-writing.tistory.com/303 by ccl(S) rewrite - 2021-09-29 07:02:21