Java Date to Quarter getQuarter(Date date)

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

Description

get Quarter

License

Open Source License

Declaration

public static int getQuarter(Date date) 

Method Source Code


//package com.java2s;

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

public class Main {

    public static int getQuarter(Date date) {
        if (date == null) {
            return 0;
        }/*  ww w  . ja  v a2s  . c o  m*/
        Calendar objCalendar = Calendar.getInstance();
        objCalendar.setTime(date);
        int iMonth = objCalendar.get(Calendar.MONTH) + 1;
        if ((iMonth >= 1) && (iMonth <= 3)) {
            return 1;
        } else if ((iMonth >= 4) && (iMonth <= 6)) {
            return 2;
        } else if ((iMonth >= 7) && (iMonth <= 9)) {
            return 3;
        } else {
            return 4;
        }
    }
}

Related

  1. getQuarter(Date date)
  2. getQuarter(Date date)
  3. getQuarter(Date date)
  4. getQuarterBounds(final Date date)
  5. getQuarterlyKey(Date d)
  6. getQuarterNum(Date date)