Here you can find the source of getQuarter(Date date)
Parameter | Description |
---|---|
date | a parameter |
public static int getQuarter(Date date)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { /**// ww w .j a v a 2 s . com * Get quarter to the date. * * @param date * @return */ public static int getQuarter(Date date) { int month = getMonth(date); int quarter = -1; switch (month) { case 1: case 2: case 3: quarter = 1; break; case 4: case 5: case 6: quarter = 2; break; case 7: case 8: case 9: quarter = 3; break; case 10: case 11: case 12: quarter = 4; break; default: break; } return quarter; } /** * Get month to the date. * * @param date * @return */ public static int getMonth(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(Calendar.MONTH) + 1; } }