Here you can find the source of getEndQuaterly(Date startDate)
public static Date getEndQuaterly(Date startDate)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static Date getEndQuaterly(Date startDate) { Calendar result = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, startDate.getYear() + 1900); calendar.set(Calendar.MONTH, startDate.getMonth()); calendar.set(Calendar.DATE, startDate.getDate()); if (calendar.get(Calendar.MONTH) <= Calendar.MARCH) { result.set(Calendar.MONTH, Calendar.MARCH); result.set(Calendar.DATE, result.getActualMaximum(Calendar.DATE)); result.set(Calendar.YEAR, calendar.get(Calendar.YEAR)); } else if (calendar.get(Calendar.MONTH) <= Calendar.JUNE) { result.set(Calendar.MONTH, Calendar.JUNE); result.set(Calendar.DATE, result.getActualMaximum(Calendar.DATE)); result.set(Calendar.YEAR, calendar.get(Calendar.YEAR)); } else if (calendar.get(Calendar.MONTH) <= Calendar.SEPTEMBER) { result.set(Calendar.MONTH, Calendar.SEPTEMBER); result.set(Calendar.DATE, result.getActualMaximum(Calendar.DATE)); result.set(Calendar.YEAR, calendar.get(Calendar.YEAR)); } else {/* w ww. jav a 2 s. c o m*/ result.set(Calendar.MONTH, Calendar.DECEMBER); result.set(Calendar.DATE, calendar.getMaximum(Calendar.DATE)); result.set(Calendar.YEAR, calendar.get(Calendar.YEAR)); } return result.getTime(); } }