How do I discover the Quarter of a given Date?

前端 未结 14 1061
小鲜肉
小鲜肉 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条回答
  •  一生所求
    2020-12-24 06:00

    I use this method.

     public static Integer getQuarter(Date d){
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        int month = c.get(Calendar.MONTH);
        return (month /3)+1;
    }
    

提交回复
热议问题