Here you can find the source of getSpcilNumDayArray(Date startDate, int num)
public static Date[] getSpcilNumDayArray(Date startDate, int num)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static final String DATE_PATTERN = "yyyy-MM-dd"; public static Date[] getSpcilNumDayArray(Date startDate, int num) { Date[] dates = new Date[2]; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try {/*from ww w . j a va 2 s. co m*/ dates[0] = sdf.parse(format(startDate, "yyyy-MM-dd")); Calendar calendar = new GregorianCalendar(); calendar.setTime(dates[0]); calendar.add(Calendar.DATE, num); calendar.add(Calendar.SECOND, -1); dates[1] = calendar.getTime(); } catch (ParseException e) { e.printStackTrace(); } return dates; } public static Date parse(String str, String formatPattern) { try { return new SimpleDateFormat(formatPattern).parse(str); } catch (ParseException e) { throw new RuntimeException("could not parse date: " + str + " LEGACY_FORMAT = " + new SimpleDateFormat(formatPattern).toPattern(), e); } } public static Date parse(String str) { if (str.length() != DATE_PATTERN.length() && str.length() != DATE_TIME_PATTERN.length()) { return null; } String formatPattern = DATE_PATTERN; if (str.length() > 10) { formatPattern = DATE_TIME_PATTERN; } try { return new SimpleDateFormat(formatPattern).parse(str); } catch (ParseException e) { throw new RuntimeException("could not parse date: " + str + " LEGACY_FORMAT = " + new SimpleDateFormat(formatPattern).toPattern(), e); } } public static String format(Date date, String formatPattern) { // Assert.notNull(date); return new SimpleDateFormat(formatPattern).format(date); } }