Here you can find the source of getQuarterStartDateBeforeCurrent(int num, Date current)
public static long getQuarterStartDateBeforeCurrent(int num, Date current)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static long getQuarterStartDateBeforeCurrent(int num, Date current) { Calendar calCurrent = Calendar.getInstance(); calCurrent.setTime(current);/*from ww w . j a v a 2 s.c om*/ int currentMonth = calCurrent.get(Calendar.MONTH) + 1; Calendar latestQuarter = Calendar.getInstance(); switch (currentMonth) { // delete by lijun begin // case 1 : // case 2 : // case 3 : {latestQuarter.set(Calendar.YEAR, // calCurrent.get(Calendar.YEAR) - 1); // latestQuarter.set(Calendar.MONTH, Calendar.OCTOBER); // break;} // case 4 : // case 5 : // case 6 : {latestQuarter.set(Calendar.YEAR, // calCurrent.get(Calendar.YEAR)); // latestQuarter.set(Calendar.MONTH, Calendar.JANUARY); // break;} // case 7 : // case 8 : // case 9 : {latestQuarter.set(Calendar.YEAR, // calCurrent.get(Calendar.YEAR)); // latestQuarter.set(Calendar.MONTH, Calendar.APRIL); // break;} // case 10 : // case 11 : // case 12 : {latestQuarter.set(Calendar.YEAR, // calCurrent.get(Calendar.YEAR)); // latestQuarter.set(Calendar.MONTH, Calendar.JULY); // break;} // delete by lijun end // add by lijun begin case 1: case 2: case 3: { latestQuarter.set(Calendar.YEAR, calCurrent.get(Calendar.YEAR)); latestQuarter.set(Calendar.MONTH, Calendar.JANUARY); break; } case 4: case 5: case 6: { latestQuarter.set(Calendar.YEAR, calCurrent.get(Calendar.YEAR)); latestQuarter.set(Calendar.MONTH, Calendar.APRIL); break; } case 7: case 8: case 9: { latestQuarter.set(Calendar.YEAR, calCurrent.get(Calendar.YEAR)); latestQuarter.set(Calendar.MONTH, Calendar.JULY); break; } case 10: case 11: case 12: { latestQuarter.set(Calendar.YEAR, calCurrent.get(Calendar.YEAR)); latestQuarter.set(Calendar.MONTH, Calendar.OCTOBER); break; } // add by lijun end } latestQuarter.set(Calendar.DAY_OF_MONTH, 1); latestQuarter.set(Calendar.HOUR_OF_DAY, 0); latestQuarter.set(Calendar.MINUTE, 0); latestQuarter.set(Calendar.SECOND, 0); latestQuarter.set(Calendar.MILLISECOND, 0); // delete by lijun begin // Calendar calQuarter = Calendar.getInstance(); // calQuarter.set(Calendar.YEAR, latestQuarter.get(Calendar.YEAR) - (num // - 1)/4); // // if ((latestQuarter.get(Calendar.MONTH) + 1 - (num - 1)%4*3) > 0) { // calQuarter.set(Calendar.MONTH, latestQuarter.get(Calendar.MONTH) - // (num - 1)%4*3); // } else { // calQuarter.set(Calendar.MONTH, Calendar.JANUARY); // } // // calQuarter.set(Calendar.DAY_OF_MONTH, 1); // calQuarter.set(Calendar.HOUR_OF_DAY, 0); // calQuarter.set(Calendar.MINUTE, 0); // calQuarter.set(Calendar.SECOND, 0); // // // return calQuarter.getTimeInMillis(); // delete by lijun end // add by lijun begin int subtractMonthNum = num * 3; latestQuarter.add(Calendar.MONTH, -subtractMonthNum); return latestQuarter.getTimeInMillis(); // add by lijun end } }