2008년 6월 24일 화요일

To make by calendar array in Java

자바로 달력 배열로 만들기 질문입니다.


//주석 필요하시면 쪽지 주세요.

import java.util.*;

import java.text.*;

class Calendar_IN

{

public static void main(String[] args)

{

String start_date = "2008-06-25";

String end_date = "2009-06-24";

String[] inner_date = null;

Calendar cs = Calendar.getInstance();

Calendar ce = Calendar.getInstance();

SimpleDateFormat sdf = new SimpleDateFormat();

sdf.applyPattern("yyyy-MM-dd");

cs=getDate(start_date);

ce=getDate(end_date);

int count=1;

while(cs.before(ce))

{

count++;

cs.add(Calendar.DATE, 1);

}

cs=getDate(start_date);

inner_date = new String[count];

for(int i=0;i<count;i++){

inner_date[i]=(sdf.format(cs.getTime()));

cs.add(Calendar.DATE, 1);

}

for(int i=0;i<count;i++){

System.out.println(inner_date[i]);

}

}

private static Calendar getDate(String date) {

// TODO Auto-generated method stub

Calendar ret=Calendar.getInstance();;

ret.setTime(new Date(Integer.valueOf(date.substring(0, 4))-1900,

Integer.valueOf(date.substring(5, 7))-1,

Integer.valueOf(date.substring(8, 10))));

return ret;

}

}

댓글 없음:

댓글 쓰기

-


Sidewinder


World


FishMusic


LaughingBaby