Java Date to Quarter getQuarterNum(Date date)

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

Description

get Quarter Num

License

Apache License

Declaration

private static int getQuarterNum(Date date) 

Method Source Code

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

import java.util.Calendar;

import java.util.Date;

public class Main {
    private static int getQuarterNum(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);/* w ww  . jav  a 2s.c  o m*/

        int currentMonth = cal.get(Calendar.MONTH) + 1;
        switch (currentMonth) {
        case 1:
        case 2:
        case 3:
            return 1;
        case 4:
        case 5:
        case 6:
            return 2;
        case 7:
        case 8:
        case 9:
            return 3;
        case 10:
        case 11:
        case 12:
            return 4;
        }

        return 0;
    }
}

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 dt)
  7. getQuarterOfDay(Date day)
  8. getQuarterStart(Date date)
  9. getQuarterYear(Date dateParam)