30 days hath September,
April, June and November,
All the rest have 31,
Excepting February alone
(And that has 28 days clear,
With 29 in each leap year).
Can I obtain this info anagrammatically? (I don't mean the poem, of course)
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();
}