public int numOccurrences ( int year , int month , int day ) { DateTimeFormatter parser = ISODateTimeFormat . date ( ) ; DateTime date = parser . parseDateTime ( year + "-" + month + "-" + "01" ) ; Calendar cal = Calendar . getInstance ( ) ; cal . setTime ( date . toDate ( ) ) ; GregorianChronology calendar = GregorianChronology . getInstance ( ) ; DateTimeField field = calendar . dayOfMonth ( ) ; int days = 0 ; int count = 0 ; int num = field . getMaximumValue ( new LocalDate ( year , month , day , calendar ) ) ; while ( days < num ) { if ( cal . get ( Calendar . DAY_OF_WEEK ) == day ) { count ++ ; } date = date . plusDays ( 1 ) ; cal . setTime ( date . toDate ( ) ) ; days ++ ; } return count ; }
Given a year month and day find the number of occurrences of that day in the month