Allain Lalonde Allain Lalonde - 10 months ago 46
Java Question

How do I discover the Quarter of a given Date?

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.


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).