If you have a DateTime object which represents a value in the month, then it’s pretty straightforward. You get the dayOfMonth property from that DateTime object and get the maximum value of the property. Here is a sample function:
public static int daysOfMonth(int year, int month) {
DateTime dateTime = new DateTime(year, month, 14, 12, 0, 0, 000);
return dateTime.dayOfMonth().getMaximumValue();
}