JSP - 달력

JSP - 달력

<%@page import="java.util.Calendar"%> <%@ page contentType="text/html; charset=UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <% request.setCharacterEncoding("utf-8"); Calendar cal = Calendar.getInstance(); // 시스템 오늘날짜 int ty = cal.get(Calendar.YEAR); int tm = cal.get(Calendar.MONTH)+1; int td = cal.get(Calendar.DATE); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH)+1; // 파라미터 받기 String sy = request.getParameter("year"); String sm = request.getParameter("month"); if(sy!=null) { // 넘어온 파라미터가 있으면 year = Integer.parseInt(sy); } if(sm!=null) { month = Integer.parseInt(sm); } cal.set(year, month-1, 1); year = cal.get(Calendar.YEAR); month = cal.get(Calendar.MONTH)+1; int week = cal.get(Calendar.DAY_OF_WEEK); // 1(일)~7(토) %> Insert title here *{ margin: 0; padding: 0; box-sizing: border-box; } body { font-size: 14px; font-family: "맑은 고딕", 나눔고딕, 돋움, sans-serif; } a { color: #000; text-decoration: none; cursor: pointer; } a:active, a:hover { text-decoration: underline; color: #F28011; } .calendar { width: 280px; margin: 30px auto; } .calendar .title{ height: 37px; line-height: 37px; text-align: center; font-weight: 600; } .calendar table { width: 100%; border-collapse: collapse; border-spacing: 0; } .calendar table thead tr:first-child{ background: #f6f6f6; } .calendar table td{ padding: 10px; text-align: center; border: 1px solid #ccc; } .calendar table td:nth-child(7n+1){ color: red; } .calendar table td:nth-child(7n){ color: blue; } .calendar table td.gray { color: #ccc; } .calendar table td.today{ font-weight:700; background: #E6FFFF; } .calendar .footer{ height: 25px; line-height: 25px; text-align: right; font-size: 12px; } < <%=year%>년 <%=month%>월 > 일 월 화 수 목 금 토 <% // 1일 앞 달 Calendar preCal = (Calendar)cal.clone(); preCal.add(Calendar.DATE, -(week-1)); int preDate = preCal.get(Calendar.DATE); out.print(""); // 1일 앞 부분 for(int i=1; i "); out.print(""+(preDate++)+""); } // 1일부터 말일까지 출력 int lastDay = cal.getActualMaximum(Calendar.DATE); String cls; for(int i=1; i<=lastDay; i++) { cls = year==ty && month==tm && i==td ? "today":""; out.print(""+i+""); if(lastDay != i && (++week)%7 == 1) { out.print(""); } } // 마지막 주 마지막 일자 다음 처리 int n = 1; for(int i = (week-1)%7; i<6; i++) { // out.print(" "); out.print(""+(n++)+""); } out.print(""); %> 오늘날짜로

<%@page import="java.util.Calendar"%> <%@ page contentType="text/html; charset=UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <% request.setCharacterEncoding("utf-8"); Calendar cal = Calendar.getInstance(); // 시스템 오늘날짜 int ty = cal.get(Calendar.YEAR); int tm = cal.get(Calendar.MONTH)+1; int td = cal.get(Calendar.DATE); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH)+1; // 파라미터 받기 String sy = request.getParameter("year"); String sm = request.getParameter("month"); if(sy!=null) { // 넘어온 파라미터가 있으면 year = Integer.parseInt(sy); } if(sm!=null) { month = Integer.parseInt(sm); } cal.set(year, month-1, 1); year = cal.get(Calendar.YEAR); month = cal.get(Calendar.MONTH)+1; int week = cal.get(Calendar.DAY_OF_WEEK); // 1(일)~7(토) %> Insert title here *{ margin: 0; padding: 0; box-sizing: border-box; } body { font-size: 14px; font-family: "맑은 고딕", 나눔고딕, 돋움, sans-serif; } a { color: #000; text-decoration: none; cursor: pointer; } a:active, a:hover { text-decoration: underline; color: #F28011; } .calendar { width: 280px; margin: 30px auto; } .calendar .title{ height: 37px; line-height: 37px; text-align: center; font-weight: 600; } .calendar .selectField { border: 1px solid #999; padding: 2px 7px; border-radius: 3px; font-family: "맑은 고딕", 나눔고딕, 돋움, sans-serif; vertical-align: baseline; } .calendar table { width: 100%; border-collapse: collapse; border-spacing: 0; } .calendar table thead tr:first-child{ background: #f6f6f6; } .calendar table td{ padding: 10px; text-align: center; border: 1px solid #ccc; } .calendar table td:nth-child(7n+1){ color: red; } .calendar table td:nth-child(7n){ color: blue; } .calendar table td.gray { color: #ccc; } .calendar table td.today{ font-weight:700; background: #E6FFFF; } .calendar .footer{ height: 25px; line-height: 25px; text-align: right; font-size: 12px; } function change() { var f = document.frm; f.action="calendar2.jsp"; f.submit(); } <% for(int i=year-5; i<=year+5; i++){ %> ><%=i%>년 <%} %> <% for(int i=1; i<=12; i++){ %> ><%=i%>월 <%} %> 일 월 화 수 목 금 토 <% // 1일 앞 달 Calendar preCal = (Calendar)cal.clone(); preCal.add(Calendar.DATE, -(week-1)); int preDate = preCal.get(Calendar.DATE); out.print(""); // 1일 앞 부분 for(int i=1; i "); out.print(""+(preDate++)+""); } // 1일부터 말일까지 출력 int lastDay = cal.getActualMaximum(Calendar.DATE); String cls; for(int i=1; i<=lastDay; i++) { cls = year==ty && month==tm && i==td ? "today":""; out.print(""+i+""); if(lastDay != i && (++week)%7 == 1) { out.print(""); } } // 마지막 주 마지막 일자 다음 처리 int n = 1; for(int i = (week-1)%7; i<6; i++) { // out.print(" "); out.print(""+(n++)+""); } out.print(""); %> 오늘날짜로

from http://heidong.tistory.com/130 by ccl(A) rewrite - 2021-10-14 23:27:20