Here you can find the source of getPreviousQuarterStartDate(Date dt)
Parameter | Description |
---|---|
dt | a parameter |
public static Date getPreviousQuarterStartDate(Date dt)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; public class Main { public static final String AM = "AM"; /**/* ww w. ja v a 2 s . co m*/ * Gets the start date for the previous quarter * * @param dt * @return the date */ public static Date getPreviousQuarterStartDate(Date dt) { Calendar cal = Calendar.getInstance(); cal.setTime(dt); int calMonth = cal.get(Calendar.MONTH); int calMonthMod = (calMonth) % 3; cal.add(Calendar.MONTH, -(calMonthMod + 3)); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH)); return dayStart(cal.getTime()); } /** * Set a Date dt to the start of the day, with the hour, minute, second and * millisecods all zeros(AM). This could be used for possible scheduling. * * @param dt * The given Date * * @return date The day end Date for the given date */ public static Date dayStart(Date dt) { Calendar cal = Calendar.getInstance(); cal.setTime(dt); cal.set(Calendar.HOUR_OF_DAY, 0); cal.get(Calendar.HOUR_OF_DAY); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.AM_PM, Calendar.AM); return cal.getTime(); } }