Here you can find the source of getMonth(Date time, int monthBefore, int monthAfter)
public static Date[] getMonth(Date time, int monthBefore, int monthAfter)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Calendar; import java.util.Date; public class Main { public static Date[] getMonth(Date time, int monthBefore, int monthAfter) { ArrayList result = new ArrayList(); Calendar calendar = Calendar.getInstance(); if (null != time) { calendar.setTimeInMillis(time.getTime()); }/*from w w w. ja v a 2 s. c om*/ for (int i = monthBefore; i <= monthAfter; i++) { Calendar calendartmp = Calendar.getInstance(); calendartmp.setTimeInMillis(calendar.getTimeInMillis()); calendartmp.set(5, 1); calendartmp.set(11, 0); calendartmp.set(12, 0); calendartmp.set(13, 0); calendartmp.set(14, 0); calendartmp.add(2, i); result.add(new Date(calendartmp.getTimeInMillis())); } return (Date[]) (Date[]) result.toArray(new Date[monthAfter - monthBefore + 1]); } public static Date[] getMonth(Date startMonth, Date endMonth) { ArrayList result = new ArrayList(); Calendar calendar = Calendar.getInstance(); Calendar calendarEnd = Calendar.getInstance(); if (null != startMonth) { calendar.setTimeInMillis(startMonth.getTime()); } if (null != endMonth) { calendarEnd.setTimeInMillis(endMonth.getTime()); } while (!calendar.after(calendarEnd)) { result.add(new Date(calendar.getTimeInMillis())); calendar.add(2, 1); } return (Date[]) (Date[]) result.toArray(new Date[result.size()]); } public static Date[] getMonth(int monthBefore, int monthAfter) { return getMonth(null, monthBefore, monthAfter); } }