Here you can find the source of getFirstDayOfQuarter(Date date)
public static Date getFirstDayOfQuarter(Date date)
//package com.java2s; import java.text.ParseException; import java.util.Calendar; import java.util.Date; public class Main { public static Date getFirstDayOfQuarter(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from ww w . j a va 2 s . c o m return getFirstDayOfQuarter(calendar.get(Calendar.YEAR), getQuarterOfYear(date)); } public static Date getFirstDayOfQuarter(Integer year, Integer quarter) { Calendar calendar = Calendar.getInstance(); Integer month = new Integer(0); if (quarter == 1) { month = 1 - 1; } else if (quarter == 2) { month = 4 - 1; } else if (quarter == 3) { month = 7 - 1; } else if (quarter == 4) { month = 10 - 1; } else { month = calendar.get(Calendar.MONTH); } return getFirstDayOfMonth(year, month); } public static int getQuarterOfYear(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(Calendar.MONTH) / 3 + 1; } public static Date getFirstDayOfMonth(Date date) throws ParseException { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 1); return calendar.getTime(); } public static Date getFirstDayOfMonth(Integer year, Integer month) { Calendar calendar = Calendar.getInstance(); if (year == null) { year = calendar.get(Calendar.YEAR); } if (month == null) { month = calendar.get(Calendar.MONTH); } calendar.set(year, month, 1); return calendar.getTime(); } }