Java Utililty Methods Date to Quarter

List of utility methods to do Date to Quarter

Description

The list of methods to do Date to Quarter are organized into topic(s).

Method

intgetQuarter(Date date)
get Quarter
Calendar cld = Calendar.getInstance();
cld.setTime(date);
Double dd = new Double(Math.floor(cld.get(Calendar.MONTH) / 3));
return dd.intValue() + 1;
intgetQuarter(Date date)
get Quarter
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int month = cal.get(Calendar.MONTH); 
int quarter = (month / 3) + 1;
return quarter;
intgetQuarter(Date date)
get Quarter
if (date == null) {
    return 0;
Calendar objCalendar = Calendar.getInstance();
objCalendar.setTime(date);
int iMonth = objCalendar.get(Calendar.MONTH) + 1;
if ((iMonth >= 1) && (iMonth <= 3)) {
    return 1;
...
intgetQuarter(Date date)
Get quarter to the date.
int month = getMonth(date);
int quarter = -1;
switch (month) {
case 1:
case 2:
case 3:
    quarter = 1;
    break;
...
Date[]getQuarterBounds(final Date date)
Returns an array of quarter bound dates of the year based on a specified date.
Objects.requireNonNull(date);
final GregorianCalendar c = gregorianCalendarThreadLocal.get();
c.setTime(date);
final int year = c.get(Calendar.YEAR);
Date[] bounds = new Date[8];
c.set(year, Calendar.JANUARY, 1, 0, 0, 0);
bounds[0] = c.getTime();
c.set(year, Calendar.MARCH, 31, 0, 0, 0);
...
StringgetQuarterlyKey(Date d)
get Quarterly Key
Calendar c = Calendar.getInstance();
c.setTime(d);
int month = c.get(Calendar.MONTH);
int q = (((month + 1) / 3) + 3) % 4 + 1;
int fy = c.get(Calendar.YEAR);
if (month >= 2) {
    fy++;
return "FY" + fy + "_Q" + q;
intgetQuarterNum(Date date)
get Quarter Num
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int currentMonth = cal.get(Calendar.MONTH) + 1;
switch (currentMonth) {
case 1:
case 2:
case 3:
    return 1;
...
intgetQuarterNum(Date dt)
get Quarter Num
if (dt == null)
    return 0;
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(dt);
int thisMonth = gc.get(Calendar.MONTH);
return thisMonth / 4 + 1;
intgetQuarterOfDay(Date day)
get Quarter Of Day
Calendar calendar = Calendar.getInstance();
calendar.setTime(day);
int month = calendar.get(Calendar.MONTH);
return month / 3;
DategetQuarterStart(Date date)
get Quarter Start
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int month = cal.get(Calendar.MONTH);
switch (month) {
case 0:
case 1:
case 2:
    cal.set(Calendar.MONTH, Calendar.JANUARY);
...