import java.util.Calendar; import java.util.Locale; import org.joda.time.DateTime; public class WochenImMonat { private static int getAnzWochen() { int year = 2010, month = 2; DateTime firstDay = new DateTime(year, month, 1, 0, 0); DateTime thisDay = firstDay; Calendar cal = firstDay.toCalendar(Locale.GERMANY); int anzDaysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); int counter = 0; while (true) { int monday = thisDay.getDayOfWeek(); if (monday == 1) { break; } thisDay = thisDay.plusDays(1); ++counter; } if (counter == 0) counter = 7; double tmpDiff = anzDaysInMonth - counter; double ausgabe = tmpDiff / 7 + 1; if(ausgabe == 4.0 && anzDaysInMonth > 28) ausgabe = ausgabe + 1; return (int) Math.ceil(ausgabe); } public static void main(String[] args) { System.out.println(getAnzWochen()); } }