john miran
john miran

Reputation: 393

How to get week of year for Jewish calendar

I try to find the week of the year for Jewish to use it in a global app, which provides general services about the international calendar.

Upvotes: 3

Views: 510

Answers (2)

Meno Hochschild
Meno Hochschild

Reputation: 44071

You might try my lib Time4J which offers a Jewish/Hebrew calendar and use following code:

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

It uses the default week model/definition in Israel which starts the week on Sunday (after Sabbat).

About interoperability with java.time:

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

Upvotes: 6

Vebbie
Vebbie

Reputation: 1695

You can refer the link here which provides example that might help you:

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));
        }
    }

Upvotes: 1

Related Questions