如何获得犹太日历的一年中的星期

时间:2018-11-28 10:12:25

标签: java calendar hebrew

我尝试查找犹太人一年中的哪个星期在全球应用程序中使用它,该应用程序提供有关国际日历的常规服务。

2 个答案:

答案 0 :(得分:3)

您可以尝试使用提供犹太/希伯来语日历的lib Time4J,并使用以下代码:

HebrewCalendar hebcal = HebrewCalendar.nowInSystemTime();
int weekOfYear = hebcal.getInt(HebrewCalendar.WEEK_OF_YEAR);

它在以色列使用default week model/definition,从星期天开始(在安息日之后)。

关于与java.time的互操作性:

LocalDate gregorian = hebcal.transform(PlainDate.class).toTemporalAccessor();
HebrewCalendar jewish = PlainDate.from(gregorian).transform(HebrewCalendar.class);

答案 1 :(得分:0)

您可以引用链接here,该链接提供了可能对您有帮助的示例:

JewishCalendar israelCalendar = new JewishCalendar(5775, JewishDate.NISSAN, 7);
    israelCalendar.setInIsrael(true); //set the calendar to Israel
    JewishCalendar chutsLaaretzCalendar = new JewishCalendar(5775, JewishDate.NISSAN, 7);
    chutsLaaretzCalendar.setInIsrael(false); //not really needed since the API defaults to false
    HebrewDateFormatter hdf = new HebrewDateFormatter();
    System.out.println("Date\tChutz Laaretz / Eretz Yisrael"));

for(int i = 0; i < 57; i++){
        israelCalendar.forward(); //roll the date forward a day
        chutsLaaretzCalendar.forward(); //roll the date forward a day
        if(chutsLaaretzCalendar.getDayOfWeek() == 7){ //ignore weekdays
            System.out.println(hdf.formatParsha(chutsLaaretzCalendar) + "\t" + hdf.formatParsha(israelCalendar) + " \\ " + hdf.format(chutsLaaretzCalendar));
        }
    }