Allain Lalonde Allain Lalonde - 1 year ago 93
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download