Java Date Previous getPreviousQuarterStartDate(Date dt)

Here you can find the source of getPreviousQuarterStartDate(Date dt)

Description

Gets the start date for the previous quarter

License

Open Source License

Parameter

Parameter Description
dt a parameter

Return

the date

Declaration

public static Date getPreviousQuarterStartDate(Date dt) 

Method Source Code

//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();
    }
}

Related

  1. getPreviousFriday(final Date d)
  2. getPreviousMonday(Date day)
  3. getPreviousMonth(Date time)
  4. getPreviousMonth(long date)
  5. getPreviousMonthFirst(Date appointDate)
  6. getPreviuosRoundMonth(Date baseDate)
  7. previousDay(Date date)
  8. previousDay(long date)
  9. previousDay(long date)