정미나닷컴
[JSP] JSP D-day 계산 본문
<%@ page import = "java.text.*" %>
<%@ page import = "java.util.*" %>
<%
// 2010 남아공 월드컵
int DdayYear = 2010;
int DdayMonth = 6;
int DdayDate = 11;
Calendar currentCalendar = Calendar.getInstance();
Calendar cal = Calendar.getInstance();
int curYear =currentCalendar.get(Calendar.YEAR);
int curMonth =currentCalendar.get(Calendar.MONTH)+1;
int curDate =currentCalendar.get(Calendar.DATE);
int nTotalDate1 = 0, nTotalDate2 = 0, nDiffOfYear = 0, nDiffOfDay = 0;
//System.out.println("오늘은 올해의 " +cal.get(Calendar.DAY_OF_YEAR)+"번째 날 입니다");
//System.out.println("오늘은 이번주의 " +cal.get(Calendar.DAY_OF_WEEK)+"번째 날 입니다");
//System.out.println("오늘은 올해의 "+cal.get(Calendar.WEEK_OF_YEAR)+"번째 주 입니다");
if(DdayYear > curYear){
for(int i=curYear; i<DdayYear; i++){
cal.set(i, 12, 0); // 2010, 12, 0
nDiffOfYear += cal.get(Calendar.DAY_OF_YEAR);
}
nTotalDate1 += nDiffOfYear;
}else if(DdayYear < curYear){
for(int i=DdayYear; i<curYear; i++){
cal.set(i, 12, 0);
nDiffOfYear += cal.get(Calendar.DAY_OF_YEAR);
}
nTotalDate2 += nDiffOfYear;
}
cal.set(DdayYear, DdayMonth-1, DdayDate);
nDiffOfDay = cal.get(Calendar.DAY_OF_YEAR);
nTotalDate1 += nDiffOfDay;
cal.set(curYear, curMonth-1, curDate);
nDiffOfDay = cal.get(Calendar.DAY_OF_YEAR);
nTotalDate2 += nDiffOfDay;
int Dday = nTotalDate1 - nTotalDate2;
%>
'IT' 카테고리의 다른 글
[jQuery] jQuery를 이용한 xml 파싱 (0) | 2010.07.02 |
---|---|
[JavaScript] 자바스크립트 iframe 자동 Resizing 함수 (0) | 2010.05.13 |
[Oracle] 오라클 데이터 변환 함수 (0) | 2010.04.26 |
[JSP] JSP 시간 비교 (0) | 2010.04.19 |
[HTML4] div 공백 제거 (웹표준) (0) | 2010.04.16 |