The number of months in a Calendar is not constant?

From, one post mentioned:

public static int monthsBetween(Date minuend, Date subtrahend)  
Calendar cal = Calendar.getInstance();  
// default will be Gregorian in US Locales  
int minuendMonth =  cal.get(Calendar.MONTH);  
int minuendYear = cal.get(Calendar.YEAR);  
int subtrahendMonth =  cal.get(Calendar.MONTH);  
int subtrahendYear = cal.get(Calendar.YEAR);  

// the following will work okay for Gregorian but will not  
// work correctly in a Calendar where the number of months   
// in a year is not constant  
return ((minuendYear - subtrahendYear) * cal.getMaximum(Calendar.MONTH)) +    
(minuendMonth - subtrahendMonth);  

Is it true that the number of months in a Calendar is not constant? And why?


Yes. In the hebrew calendar, there are several years with 13 months (7 out of 19 to be exact).

Leave a Reply

Your email address will not be published. Required fields are marked *