Java Date to Quarter getQuarterStart(Date date)

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

Description

get Quarter Start

License

Open Source License

Declaration

public static Date getQuarterStart(Date date) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static Date getQuarterStart(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);//from   w ww .  ja va 2s .co m
        int month = cal.get(Calendar.MONTH);
        switch (month) {
        case 0:
        case 1:
        case 2:
            cal.set(Calendar.MONTH, Calendar.JANUARY);
            break;
        case 3:
        case 4:
        case 5:
            cal.set(Calendar.MONTH, Calendar.APRIL);
            break;
        case 6:
        case 7:
        case 8:
            cal.set(Calendar.MONTH, Calendar.JULY);
            break;
        case 9:
        case 10:
        case 11:
            cal.set(Calendar.MONTH, Calendar.OCTOBER);
            break;
        default:
            break;
        }
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);

        return cal.getTime();
    }
}

Related

  1. getQuarterBounds(final Date date)
  2. getQuarterlyKey(Date d)
  3. getQuarterNum(Date date)
  4. getQuarterNum(Date dt)
  5. getQuarterOfDay(Date day)
  6. getQuarterYear(Date dateParam)
  7. getQuaterStart(Date date)