How do I discover the Quarter of a given Date?

前端 未结 14 1126
小鲜肉
小鲜肉 2020-12-24 05:37

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.

14条回答
  •  萌比男神i
    2020-12-24 06:09

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

提交回复
热议问题