관리 메뉴

I LOVE EJ

지정된 날짜에 for문 이용하여 +7일씩 하기 본문

Web Development/JSP

지정된 날짜에 for문 이용하여 +7일씩 하기

BeOne 2008. 8. 10. 14:46

<%@ page contentType="text/html; charset=euc-kr" language="java" import="java.sql.*" errorPage="" %>
<% request.setCharacterEncoding("euc-kr"); %>
<%@ page import="java.util.*, java.text.*"%>
<%@ page import="common.util.*"%>

<%

 DecimalFormat df = new DecimalFormat("00");
 Calendar currentCalendar = Calendar.getInstance();

 currentCalendar.set(Calendar.YEAR, Integer.parseInt("2008"));
 currentCalendar.set(Calendar.MONTH, Integer.parseInt("8") - 1);
 currentCalendar.set(Calendar.DATE, Integer.parseInt("10")); 

 for(int i=0; i<30; i++){
  String strYear = Integer.toString(currentCalendar.get(Calendar.YEAR));
  String strMonth = df.format(currentCalendar.get(Calendar.MONTH) + 1);
  String strDay = df.format(currentCalendar.get(Calendar.DATE));
  String strDate = strYear+"-"+strMonth+"-"+strDay;
 
%>
<%=strDate%><br>
<%
  //다음 날짜를 구해냄
  currentCalendar.add(currentCalendar.DATE, 7);
 }
%>