您可以使用我的库Time4J,它提供了确定以年、月或日为单位测量的差异的功能。示例(来自 JUnit 测试用例):
HebrewCalendar start = HebrewCalendar.of(5778, HebrewMonth.HESHVAN, 6);
HebrewCalendar end = HebrewCalendar.of(5778, HebrewMonth.ELUL, 6);
assertThat(HebrewCalendar.Unit.MONTHS.between(start, end), is(10));
start = start.plus(CalendarDays.ONE);
assertThat(HebrewCalendar.Unit.MONTHS.between(start, end), is(9));
start = start.minus(3, HebrewCalendar.Unit.YEARS);
assertThat(HebrewCalendar.Unit.YEARS.between(start, end), is(3));
start = start.plus(6, HebrewCalendar.Unit.YEARS).minus(CalendarDays.of(2)); // AM-5781-HESHVAN-5
assertThat(HebrewCalendar.Unit.YEARS.between(start, end), is(-2));
start = start.with(HebrewCalendar.MONTH_OF_YEAR, HebrewMonth.ELUL); // AM-5781-ELUL-5
assertThat(HebrewCalendar.Unit.MONTHS.between(start, end), is(-36));
start = start.plus(CalendarDays.ONE);
assertThat(HebrewCalendar.Unit.MONTHS.between(start, end), is(-37));
start = start.minus(37, HebrewCalendar.Unit.MONTHS);
assertThat(start, is(end));
该逻辑在某种程度上类似于java.time-package 中的标准逻辑。当结束日期的日期小于开始日期的日期时,计算的月份增量(或年份增量)将减一。
一般来说,我不建议尝试使用固定因子将天数转换为月数或年数,因为希伯来历法有时是 12 个月,有时是 13 个月。我的库也没有尝试过,而是应用了一种优化的计数。 如果没有关于开始或结束日期的任何进一步信息,也无法将日增量转换为月增量,主要原因是:
Imagine the SAME day delta had been determined with a start date
short before Adar I (leap month) or with another month later. Then the month
delta will be different because the second case does not include a leap month!
更多关于如何处理希伯来日历的例子可以在API online看到。
如果您使用的是 Android,请使用具有类似 API 的专用派生类 Time4A。