1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | /** * <PRE> * 날짜를 문자로 [Util.replaceStr(20040708,-); -> 2004-07-08] <br> * 문자를 날짜로 [replaceDate(2004-07-08, ""); -> 20040708] <br> * ClassName : CalendarUtil <br> * MethodName : replaceDate <br> * 처리내용 : * - Biz Logic (간략) * 날짜를 문자로 [Util.replaceStr(20040708,-); -> 2004-07-08] * 문자를 날짜로 [replaceDate(2004-07-08, ""); -> 20040708] * </PRE> * @return String * @param src 원소스 * @param sReplace 추가할 구분자 */ public static String replaceDate(String src, String sReplace){ String sdate = ""; if ((src == null) || (src.equals(""))){ return ""; } else { int i = src.length(); if (i == 8){ String nyear = src.substring(0, 4); String nmonth = src.substring(4, 6); String nday = src.substring(6, 8); sdate = nyear+sReplace+nmonth+sReplace+nday; } else if (i == 10) { String nyear = src.substring(0, 4); String nmonth = src.substring(5, 7); String nday = src.substring(8, 10); sdate = nyear+nmonth+nday; } else if (i == 14) { String nyear = src.substring(0, 4); String nmonth = src.substring(4, 6); String nday = src.substring(6, 8); sdate = nyear+sReplace+nmonth+sReplace+nday; } else { sdate = src; } return sdate; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | /** * <PRE> * 두 날짜 사이의 간격처리 [getDateInterval("20121121","20130205") = 75] <br> * ClassName : CalendarUtil <br> * MethodName : getDateInterval <br> * @Author : 공통 * 처리내용 : * - Biz Logic (간략) * 두 날짜 사이의 간격처리 [getDateInterval("20121121","20130205") = 75] * </PRE> * @return int * @param sdate 시작일 * @param edate 종료일 */ public static int getDateInterval(String sdate, String edate){ int ii = 0; if (sdate.equals("") || edate.equals("0")) { ii = 0; } else { int year1 = 0; int mon1 = 0; int day1 = 0; int year2 = 0; int mon2 = 0; int day2 = 0; try{ year1 = Integer.parseInt(sdate.substring(0,4)); mon1 = Integer.parseInt(sdate.substring(4,6)); day1 = Integer.parseInt(sdate.substring(6,8)); year2 = Integer.parseInt(edate.substring(0,4)); mon2 = Integer.parseInt(edate.substring(4,6)); day2 = Integer.parseInt(edate.substring(6,8)); Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.set(Calendar.YEAR,year1); cal1.set(Calendar.MONTH,mon1); cal1.set(Calendar.DATE,day1); cal2.set(Calendar.YEAR,year2); cal2.set(Calendar.MONTH,mon2); cal2.set(Calendar.DATE,day2); long val = (cal2.getTimeInMillis() - cal1.getTimeInMillis()) / 1000 / 60 / 60 / 24 ; ii = Integer.parseInt(Long.toString(val))+1; } catch (Exception e) { } finally { } } return ii; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /** * <PRE> * Calendar Date를 DB형태 날짜 문자열로 ("20000415") <br> * ClassName : CalendarUtil <br> * MethodName : gCalToDBDayString <br> * 처리내용 : * - Biz Logic (간략) * Calendar Date를 DB형태 날짜 문자열로 ("20000415") * </PRE> * @return String * @param cal GregorianCalendar 객체 */ public static String gCalToDBDayString(GregorianCalendar cal) { int year = cal.get(GregorianCalendar.YEAR); int month = cal.get(GregorianCalendar.MONTH) + 1; int date = cal.get(GregorianCalendar.DATE); return Integer.toString(year) + ((month < 10) ? "0" + month : Integer.toString(month)) + ((date < 10) ? "0" + date : Integer.toString(date)); } |
댓글 없음:
댓글 쓰기