How do I discover the Quarter of a given Date?

Allain Lalonde picture Allain Lalonde · Nov 19, 2008 · Viewed 80.4k times · Source

Given a java.util.Date object how do I go about finding what Quarter it's in?

Assuming Q1 = Jan Feb Mar, Q2 = Apr, May, Jun, etc.

Answer

Bill the Lizard picture Bill the Lizard · Nov 19, 2008

You could use

int quarter = (myDate.getMonth() / 3) + 1;

Be warned, though that getMonth is deprecated:

As of JDK version 1.1, replaced by Calendar.get(Calendar.MONTH).