¼Ò½º Å©¸®´ÐÀ» ¹Þ°í ½Í½À´Ï´Ù.(³¯Â¥°ü·Ã)


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

±Û¾´ÀÌ :°­¼ø±â 2000³â 6¿ù 22ÀÏ 12:25:34

¾Æ·¡¿Í °°Àº Äڵ带 ÀÛ¼ºÇÏ¿´´Âµ¥..
Á¦°¡ º¸±â¿¡µµ ¹º°¡ ¸ðÀÚ¶õ°Í °°¾Æ¼­....
°í¼ö´ÔµéÀÇ Á¶¾ðÀ» ¹Ù¶ø´Ï´Ù.
ƯÈ÷ ¾Æ·¡ÀÇ ÄÚµåÁß 3°¡Áö Ç׸ñÀ» Á» ºÁÁֽðí Á¶¾ðÀ»
1. Calendar typeÀ¸·Î Àμö¸¦ ¹Þ¾Ò´Âµ¥ Ŭ·¡½º·Î ·¹ÇÁ·±½º ŸÀÔÀ¸·Î
Àμö°¡ Àü´ÞµË´Ï´Ù. ±×°ÍÀ» ȸÇÇÇÏ´Â ¹æ¹ýÀ¸·Î
a_date = (Calendar)date.clone()
À» »ç¿ëÇߴµ¥ a_dateµµ calendar typeÀε¥ ¿Ö ÄɽºÆÃÀ» ÇؾßÇÏ´ÂÁö..


2. CalendarÀÇ ³¯Â¥¸¸ °¡Áö°í ºñ±³¸¦ ÇÒ·Á°í Çϴµ¥ ºñ±³ÇÒ ¼ö ÀÖ´Â ¹æ¹ý.
(Áï 1999/09/01 10:20 ÀÌ 1999/09/01 11:20°ú ºñ±³ÇÒ °æ¿ì
°°´Ù ¶ó°í ³ª¿Í¾ßÇϴµ¥ .....)


3. Àϼö °è»ê ºÎºÐÀÔ´Ï´Ù. Àüü Àϼö¸¦ °¡Áö°í °è»êÇÏÁö ¾Ê°í(¾Æ·¡ ÄÚµå¿Í °°ÀÌ)
´Ü¼øÈ÷ ÀÏÀÚ¸¦ Â÷°¨ÇÏ¿© Àϼö¸¦ °è»êÇÏ´Â ¹æ¹ýÀÌ ÀÖ´ÂÁö.
(¿©·¯°¡Áö Q&A¿¡ Date typeÀº °è»êÇÏ´Â °Í °°Àºµ¥ Calendar Type
·Î °è»êÀ» ÇÏ´Ï ¿¡¶ó°¡ ....)



import java.util.*;
import java.text.*;


public class DateCal
{
private static Calendar wk_Date_fm, wk_Date_to;


// ¿ùÀÇ ¸»ÀÏ °è»ê
public static Calendar DateMLast(Calendar date) throws Exception
{
wk_Date_fm = (Calendar)date.clone();
int dd = wk_Date_fm.getActualMaximum(Calendar.DATE);
wk_Date_fm.set(Calendar.DATE, dd);
return wk_Date_fm;
}


// ¿ùÀÇ ¸»ÀÏ °è»ê
public static Calendar DateMLast(String sdate) throws Exception
{
wk_Date_fm = DateFun.StringToCalendar(sdate);
return DateMLast(wk_Date_fm);
}


// ÇØ´ç °³¿ù ¼ö ¸¸Å­ Áõ°¡ ȤÀº °¨¼ÒÇÑ ÀÏÀÚ °è»ê
public static Calendar DateMDue(Calendar date, int mcnt)
throws Exception
{
wk_Date_fm = (Calendar)date.clone();
wk_Date_fm.add(Calendar.MONTH, mcnt);
return wk_Date_fm;
}


//ÇØ´ç Àϼö ¸¸Å­ Áõ°¡ ȤÀº °¨¼ÒÇÑ ÀÏÀÚ
public static Calendar DateDDue(Calendar date, int dcnt)
throws Exception
{
wk_Date_fm = (Calendar)date.clone();
wk_Date_fm.add(Calendar.DATE, dcnt);
return wk_Date_fm;
}


// µÎ ³¯Â¥ »çÀÌÀÇ °³¿ù ¼ö ¹× ÀÜ¿© Àϼö °è»ê
public static final int[] DateMcnt(Calendar fm_date,Calendar to_date)
throws Exception
{
int[] mdcnt = {0,0};
int mcnt = 0;
int dcnt = 0;
boolean fm_date_last = false;
boolean to_date_last = false;
int fm_year, fm_month, fm_dd = 0;
int to_year, to_month, to_dd = 0;
int fm_max_dd, to_max_dd = 0;


wk_Date_fm = (Calendar)fm_date.clone();
wk_Date_to = (Calendar)to_date.clone();
Calendar wk_date = (Calendar)fm_date.clone();


fm_year = wk_Date_fm.get(Calendar.YEAR);
fm_month = wk_Date_fm.get(Calendar.MONTH) + 1;
fm_dd = wk_Date_fm.get(Calendar.DATE);
to_year = wk_Date_to.get(Calendar.YEAR);
to_month = wk_Date_to.get(Calendar.MONTH) + 1;
to_dd = wk_Date_to.get(Calendar.DATE);


mcnt = ((to_year - 1 ) * 12 + to_month)
- ((fm_year - 1 ) * 12 + fm_month);


// to_date < fm_date error
// if (mcnt < 0)
// throw e;



wk_date.add(Calendar.MONTH, mcnt);


// ½ÃÀÛÀÏÀÚ ¹× Á¾·áÀÏÀÚ°¡ ¿ù¸»ÀÎÁö °Ë»ç
// ¿©±â¼­ Equals Method¸¦ ¾µ¼ö°¡ ¾ø´Ù
// ¿Ö³ÄÇÏ¸é ½Ã°£±îÁö ´Ù ºñ±³Çϱ⠶§¹®¿¡
// ¹æ¹ýÀÌ ¾øÀ»±î?



if (wk_Date_fm.get(Calendar.DAY_OF_MONTH) ==
wk_Date_fm.getActualMaximum(Calendar.DAY_OF_MONTH))
fm_date_last = true;
if (wk_Date_to.get(Calendar.DAY_OF_MONTH) ==
wk_Date_to.getActualMaximum(Calendar.DAY_OF_MONTH))
to_date_last = true;


// fm_date¿Í to_date°¡ µÑ´Ù ¿ù¸»À̰ųª
// to_date°¡ ¿ù¸»ÀÌ°í fm_dateÀÇ ÀÏÀÚ°¡ to_dateÀÇ ÀÏÀÚº¸´Ù Ä¿¸é // ¸¸¿ùÀÌ´Ù.


if ((fm_date_last && to_date_last) ||
(to_date_last && (fm_dd >= to_dd)))
dcnt = 0;
else
// Àϼö Â¥Åõ¸®°¡ ³²´Â´Ù.
if (fm_dd <= to_dd)
dcnt = DateDcnt(wk_date, wk_Date_to);
else
// ÇÑ´ÞÀÌ ¸ðÀÚ¶õ´Ù.
{
mcnt--;
wk_date.add(Calendar.MONTH, -1);
dcnt = DateDcnt(wk_date, wk_Date_to);
}


mdcnt[0] = mcnt;
mdcnt[1] = dcnt;


return mdcnt;
}


// Àϼö °è»ê...
public static int DateDcnt(Calendar fm_date, Calendar to_date)
throws Exception
{
wk_Date_fm = (Calendar)fm_date.clone();
wk_Date_to = (Calendar)to_date.clone();
Calendar wk_date = (Calendar)fm_date.clone();
int wk_year = wk_date.get(Calendar.YEAR);
int to_year = wk_Date_to.get(Calendar.YEAR);
int dcnt = 0;


// while µµ´Â ºÎºÐÀÌ ¿µ ÂòÂòÇÏ´Ù.....
// ²À ÀÌ·¸°Ô µ¹¾Æ¾ß¸¸ µÇ´Â°¡?
while (wk_year < to_year)
{
wk_date.set(wk_year, 11, 31);
dcnt += wk_date.getActualMaximum(Calendar.DATE);
wk_year++;
}


dcnt += wk_Date_to.get(Calendar.DAY_OF_YEAR)
- wk_Date_fm.get(Calendar.DAY_OF_YEAR);


/* ÀÌ·¸°Ô °è»êÇÏ´Â ¹æ¹ýÀÌ ÀÖ¾î¾ß Çϴµ¥......
dcnt = (to_date.getTime().getDate()
- fm_date.getTime().getDate() ) /
( 1000 * 60 * 60 * 24);
*/



return dcnt;
}


}



´ÙÀ½ ±Ûµé:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
HTML ÅÂ±× Æ÷ÇÔ ¿©ºÎ: HTML ¹®¼­ÀÏ °æ¿ì üũ
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]