标签:
1.往后推时间
public static Date getNextWorkingDay(int period) throws DBException { CodeMgr codeMgr = (CodeMgr) BizMgrRegistry.getInstance().getBizMgr( "com.leapii.code.bm.CodeMgr"); Collection publicHolidayCollection = codeMgr .getCodeByType(DORMConstants.PUBLIC_HOLIDAY); Calendar currentDay = Calendar.getInstance(TimeZone .getTimeZone("GMT+08")); currentDay.setTime(DateUtil.getDate()); for (int i = 0; i < period; i++) { boolean isPublicHoliday = false; currentDay.set(Calendar.DATE, currentDay.get(Calendar.DATE) + 1); String currenDayStr = DateUtil.format(currentDay.getTime(), "yyyyMMdd"); System.out.println(currenDayStr); Iterator itr = publicHolidayCollection.iterator(); while (itr.hasNext()) { Code code = (Code) itr.next(); if (code.getValue().equals(currenDayStr)) { isPublicHoliday = true; break; } } int dayOfWeek = currentDay.get(Calendar.DAY_OF_WEEK); if (Calendar.SATURDAY == dayOfWeek || Calendar.SUNDAY == dayOfWeek || isPublicHoliday) { System.out.println("Weekend Or Public Holiday"); period = period + 1; } } return currentDay.getTime(); }
2.往前推时间
public static Date getLastWorkingDay(int period) throws DBException { CodeMgr codeMgr = (CodeMgr) BizMgrRegistry.getInstance().getBizMgr( "com.leapii.code.bm.CodeMgr"); Collection publicHolidayCollection = codeMgr .getCodeByType(DORMConstants.PUBLIC_HOLIDAY); Calendar currentDay = Calendar.getInstance(TimeZone .getTimeZone("GMT+08")); currentDay.setTime(DateUtil.getDate()); for (int i = 0; i < period; i++) { boolean isPublicHoliday = false; currentDay.set(Calendar.DATE, currentDay.get(Calendar.DATE) - 1); String currenDayStr = DateUtil.format(currentDay.getTime(), "yyyyMMdd"); System.out.println(currenDayStr); Iterator itr = publicHolidayCollection.iterator(); while (itr.hasNext()) { Code code = (Code) itr.next(); if (code.getValue().equals(currenDayStr)) { isPublicHoliday = true; break; } } int dayOfWeek = currentDay.get(Calendar.DAY_OF_WEEK); if (Calendar.SATURDAY == dayOfWeek || Calendar.SUNDAY == dayOfWeek || isPublicHoliday) { System.out.println("Weekend Or Public Holiday"); period = period + 1; } } return currentDay.getTime(); }
标签:
原文地址:http://www.cnblogs.com/jianlun/p/4942283.html