日历中的月数不是恒定的?

时间:2011-08-01 15:07:01

标签: java calendar

来自http://www.coderanch.com/t/381676/java/java/number-months-between-two-given,提到了一个帖子:

public static int monthsBetween(Date minuend, Date subtrahend)  
{  
Calendar cal = Calendar.getInstance();  
// default will be Gregorian in US Locales  
cal.setTime(minuend);  
int minuendMonth =  cal.get(Calendar.MONTH);  
int minuendYear = cal.get(Calendar.YEAR);  
cal.setTime(subtrahend);  
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);  
}  

日历中的月数不是恒定的吗?为什么?

2 个答案:

答案 0 :(得分:9)

是。在希伯来日历中,有几年有13个月(确切地说是19个中的7个)。

答案 1 :(得分:-1)

有趣的是,来自 moon 。农历通常与月相同步,因此,例如,任何月份的第15天总是满月日。

问题是太阳年不完全是12个月球周期。因此,农历必须有“闰月”。