Java examples for java.util:Quarter
which Quarter
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static void main(String[] argv) throws Exception { Date date = new Date(); System.out.println(whichQuarter(date)); }//from www .j av a 2 s. c o m public static int whichQuarter(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); int month = cal.get(Calendar.MONTH); int quarter = 0; switch (month) { case 0: case 1: case 2: quarter = 0; break; case 3: case 4: case 5: quarter = 3; break; case 6: case 7: case 8: quarter = 6; break; case 9: case 10: case 11: quarter = 9; break; } return quarter; } }