<p>刚才,我在我的库<a href="https://github.com/MenoData/Time4J" rel="nofollow noreferrer">Time4J</a>中发布了另一个希伯来日历的实现。从公历日期到<a href="http://time4j.net/javadoc-en/net/time4j/calendar/HebrewCalendar.html" rel="nofollow noreferrer">Hebrew date</a>(作为对象或格式化字符串)的转换示例:</p>
<pre><code>PlainDate gregorian = PlainDate.nowInSystemTime();
HebrewCalendar hebrew = gregorian.transform(HebrewCalendar.axis());
System.out.println(hebrew.toString()); // AM-5778-KISLEV-09
ChronoFormatter<CalendarDate> hfFull =
ChronoFormatter.ofGenericCalendarStyle(
DisplayMode.FULL,
Locale.forLanguageTag("en-US-u-ca-hebrew")
);
System.out.println(hfFull.format(gregorian)); // Monday, 9 Kislev 5778
</code></pre>
<p>国际化基于与ICU4J相同的i18n数据(实际上是CLDR-v32)。当然,希伯来语也是可能的。在</p>
^{pr2}$
<p>最后两个格式化示例展示了如何支持<strong>两种不同的希伯来月份编号方式,如果需要月份的数字输出。在</p>
<p><strong>注意:</strong>实际时间的转换也取决于时钟时间,因为希伯来语的一天从日落开始</strong>。在上面的例子中,改变一天的时间仅仅是前一天的下午6点(<a href="http://time4j.net/javadoc-en/net/time4j/calendar/HebrewCalendar.html#nowInSystemTime " rel="nofollow noreferrer">simplified view</a>)。如果您想考虑真实的日落,那么只要指定地理位置,您可以按以下方式进行:</p>
<pre><code>SolarTime jerusalem = SolarTime.ofJerusalem();
HebrewCalendar currentHebrewDate =
SystemClock.currentMoment().toGeneralTimestamp(
HebrewCalendar.axis(),
Timezone.ofSystem().getID(),
StartOfDay.definedBy(jerusalem.sunset())
).toDate();
</code></pre>