Java examples for java.util:Quarter
get First Day Of Quarter
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main{ public static void main(String[] argv) throws Exception{ Date date = new Date(); System.out.println(getFirstDayOfQuarter(date)); }//from ww w . jav a 2s . c om private static SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); public static String getFirstDayOfQuarter(Date date) { int quarter = CalendarUtil.whichQuarter(date); Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.MONTH, quarter); cal.set(Calendar.DAY_OF_MONTH, 1); date = cal.getTime(); // date.setDate(1); return sf.format(date); } public static int whichQuarter(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); int month = cal.get(Calendar.MONTH); int quarter = 0; switch (month) { case 0: case 1: case 2: quarter = 0; break; case 3: case 4: case 5: quarter = 3; break; case 6: case 7: case 8: quarter = 6; break; case 9: case 10: case 11: quarter = 9; break; } return quarter; } }