Java Date to Quarter getQuaterStart(Date date)

Here you can find the source of getQuaterStart(Date date)

Description

get Quater Start

License

LGPL

Declaration

public static Date getQuaterStart(Date date) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static java.util.Calendar.*;

public class Main {
    public static Date getQuaterStart(Date date) {
        Calendar cal = cal(date, 0, 0);
        int quater = cal.get(MONTH) / 3;
        cal.set(MONTH, quater * 3);/*from   w ww.ja  v a 2 s  .  c o  m*/
        cal.set(DATE, 1);
        return cal.getTime();
    }

    public static Calendar cal(Date date) {
        if (date == null) {
            return null;
        } else {
            return cal(date.getTime());
        }
    }

    public static Calendar cal(Date date, Integer hour, Integer minutes) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(HOUR_OF_DAY, hour);
        calendar.set(MINUTE, minutes);
        calendar.set(SECOND, 0);
        calendar.set(MILLISECOND, 0);
        return calendar;
    }

    public static Calendar cal(long millis) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(millis);
        return calendar;
    }

    public static Calendar cal(int year, int month, int date) {
        return new GregorianCalendar(year, month, date);
    }

    public static Calendar cal(int year, int month, int date, int hour, int minutes) {
        return new GregorianCalendar(year, month, date, hour, minutes);
    }
}

Related

  1. getQuarterNum(Date date)
  2. getQuarterNum(Date dt)
  3. getQuarterOfDay(Date day)
  4. getQuarterStart(Date date)
  5. getQuarterYear(Date dateParam)