Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Calendar; public class Main { public static final int TYPE_DAY = 1; public static final int TYPE_WEEK = 2; public static final int TYPE_MONTH = 3; public static final int TYPE_YEAR = 4; public static int getItemsCounts(int periodType, long date) { switch (periodType) { case TYPE_DAY: return 24; case TYPE_WEEK: return 7; case TYPE_MONTH: { Calendar c = Calendar.getInstance(); c.setTimeInMillis(date); return c.getMaximum(Calendar.DAY_OF_MONTH); } case TYPE_YEAR: { Calendar c = Calendar.getInstance(); c.setTimeInMillis(date); return c.getMaximum(Calendar.MONTH) + 1; } } return 0; } }