Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Calendar; public class Main { public static int getNumberOfWeeksInCurrentMonth() { Calendar calendar = getCalendarWithTime(getStartOfCurrentMonth()); return calendar.getActualMaximum(Calendar.WEEK_OF_MONTH); } public static Calendar getCalendarWithTime(long time) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); return calendar; } public static long getStartOfCurrentMonth() { Calendar calendar = getCurrentCalendar(); calendar.set(Calendar.DAY_OF_MONTH, 1); return calendar.getTimeInMillis(); } public static Calendar getCurrentCalendar() { return getCalendarWithTime(System.currentTimeMillis()); } }