How do I discover the Quarter of a given Date?

前端 未结 14 1127
小鲜肉
小鲜肉 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:14

    Make sure that the thisMonth is at least a float or a double, not an int:

    String quarter = thisMonth/3 <= 1 ? "Q1" : thisMonth/3 <= 2 ? "Q2" : thisMonth/3 <= 3 ? "Q3" : "Q4";
    

    Regards, MS

提交回复
热议问题