public static void main(String[] args) { List<String> list = new ArrayList<String>();//节假日列表,正式环境中根据日期条件从数据库中获取 list.add("2017-06-24"); list.add("2017-06-25"); list.add("2017-07-01"); list.add("2017-07-02"); list.add("2017-07-08"); list.add("2017-07-09"); Date curDate = getDate("2017-06-23"); int days = 3; for (int i = 1; i <= days;) { curDate = addDays(curDate); if(!list.contains(new SimpleDateFormat("yyyy-MM-dd").format(curDate))){ i++; } } System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(curDate)); } public static Date addDays(Date date) { Calendar calendar = new GregorianCalendar(); calendar.setTime(date); calendar.add(Calendar.DATE, 1); return calendar.getTime(); } public static Date getDate(String str) { try { return new SimpleDateFormat("yyyy-MM-dd").parse(str); } catch (ParseException ex) { Logger.getLogger(T05.class.getName()).log(Level.SEVERE, null, ex); } return null; }
时间: 2024-10-13 18:35:15