Here you can find the source of getLastDateOfQuarter()
public static String getLastDateOfQuarter()
//package com.java2s; //License from project: Open Source License import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class Main { public static Timestamp getLastDateOfQuarter(int year, int quarter) { // checkYearAndQuarter(year, quarter); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, 3 * quarter); calendar.set(Calendar.DATE, 1); calendar.add(Calendar.DATE, -1); return new Timestamp(calendar.getTime().getTime()); }//ww w . ja va 2s . c om public static String getLastDateOfQuarter() { Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; int quater = (month + 2) / 3; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); return formatter.format(getLastDateOfQuarter(year, quater)); } public static Timestamp format(Timestamp time) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String date = sdf.format(time); date = date.substring(0, 10) + " 00:00:00"; time = new Timestamp(sdf.parse(date).getTime()); return time; } }