The recently released Zmanim API 1.3.0 added Jewish calendar support to the API. Previously, the API had zmanim support, but no Jewish calendar support. While the calendar code is in beta mode and is subject to API changes, below are some simple code examples using the current 1.3.0 release. These examples of the use of the JewishCalendar and HebrewDateFormatter classes do not fully cover the functionality available in the Zmanim API. Please read the Javadocs and experiment. Please let me know if there are any calendar-related items that you feel should change or be added to the API.
Setting and outputting formatted dates
JewishCalendar jd = new JewishCalendar(5773, JewishDate.NISSAN, 23); // 23 Nissan, 5773
HebrewDateFormatter hdf = new HebrewDateFormatter();
System.out.println(jd); // prints the Hebrew date in English characters - 23 Nissan, 5773
hdf.setHebrewFormat(true); // change formatting to Hebrew
System.out.println(hdf.format(jd)); // date formatted in Hebrew
jd.setJewishDate(5729, JewishDate.SHEVAT, 21); // set the date to 21 Shevat, 5729
System.out.println(hdf.format(jd)); // date formatted in Hebrew
jd.setJewishDate(5772, JewishDate.NISSAN, 18); // set the date to the fourth day of Pesach
System.out.println(hdf.format(jd));
System.out.println(hdf.formatYomTov(jd)); // output Chol Hamoed Pesach in Hebrew
hdf.setHebrewFormat(false); // change formatting to the default
System.out.println(hdf.format(jd)); // prints the Hebrew date in English characters - 18 Nissan, 5772
System.out.println(hdf.formatYomTov(jd)); // output Chol Hamoed PesachOutput:
23 Nissan, 5773
כ״ג ניסן תשע״ג
כ״א שבט תשכ״ט
י״ח ניסן תשע״ב
חול המועד פסח
18 Nissan, 5772
Chol Hamoed PesachParshas Hashavua
Please note that the parsha will only be output if the date is a Shabbos. To get the parsha of the coming Shabbos on a weekday, use getUpcomingParshah(), which was added to the API after this article was written.
HebrewDateFormatter hdf = new HebrewDateFormatter();
JewishCalendar jd = new JewishCalendar(5773, JewishDate.NISSAN, 12);
System.out.println(hdf.formatParshah(jd));
hdf.setHebrewFormat(true);
System.out.println(hdf.formatParshah(jd));
jd.minusDays(1);
System.out.println("Parsha on Friday [" + hdf.formatParshah(jd) + "]"); // no parsha output on a weekday
System.out.println("Upcoming parsha [" + hdf.formatParshah(jd.getUpcomingParshah()) + "]"); // the coming Shabbos's parsha
jd.setJewishDate(5773, JewishDate.TAMMUZ, 28); // double parsha
System.out.println(hdf.formatParshah(jd));Output:
Tzav
צו
Parsha on Friday []
Upcoming parsha [צו]
מטות מסעיRosh Chodesh
HebrewDateFormatter hdf = new HebrewDateFormatter();
JewishCalendar jd = new JewishCalendar(5773, JewishDate.NISSAN, 1);
if (jd.isRoshChodesh()) { // not necessary for the formatter
System.out.println(hdf.formatRoshChodesh(jd));
}
hdf.setHebrewFormat(true);
System.out.println(hdf.formatRoshChodesh(jd));
jd.plusDays(1); // roll the calendar to the second day of Nissan
System.out.println("output[" + hdf.formatRoshChodesh(jd) + "]"); // no Rosh Chodesh outputOutput:
Rosh Chodesh Nissan
ראש חודש ניסן
output[]Daf Yomi
JewishCalendar jd = new JewishCalendar(5773, JewishDate.NISSAN, 13);
HebrewDateFormatter hdf = new HebrewDateFormatter();
System.out.println(hdf.format(jd)); // output the formatted date "13 Nissan, 5773"
Daf daf = jd.getDafYomiBavli(); // get the daf for the date
System.out.println(daf.getMasechtaTransliterated()); // output the transliterated masechta name "Eruvin"
System.out.println(daf.getDaf()); // output the daf (page) number "16"
System.out.println(hdf.formatDafYomiBavli(daf)); // output the formatted daf "Eruvin 16"
hdf.setHebrewFormat(true); // set the formatter to Hebrew
System.out.println(hdf.format(jd)); // output the date in Hebrew "י״ג ניסן תשע״ג"
System.out.println(daf.getMasechta()); // output the masechta name in Hebrew "עירובין"
System.out.println(hdf.formatHebrewNumber(daf.getDaf())); // output the daf number formatted in Hebrew "ט״ז"
System.out.println(hdf.formatDafYomiBavli(daf)); // output the daf and masechta in Hebrew "עירובין ט״ז"Output:
13 Nissan, 5773
Eruvin
16
Eruvin 16
י״ג ניסן תשע״ג
עירובין
ט״ז
עירובין ט״זChanukah
JewishCalendar jd = new JewishCalendar(5772, JewishDate.KISLEV, 25); // set the date to the first day of Chanukah
HebrewDateFormatter hdf = new HebrewDateFormatter();
System.out.println(jd); // output the transliterated date
System.out.println(jd.getDayOfChanukah()); // output 1
System.out.println(hdf.formatYomTov(jd)); // output Chanukah 1
hdf.setHebrewFormat(true); // set the format to Hebrew
System.out.println(hdf.formatHebrewNumber(jd.getDayOfChanukah())); // output 1 in Hebrew
System.out.println(hdf.formatYomTov(jd)); // output Chanukah 1 in HebrewOutput:
25 Kislev, 5772
1
Chanukah 1
א׳
א׳ חנוכהNote that there is no simple way at this point to output just Chanukah. This will likely change in the future to match Chanukah to the behavior of other Yomim Tovim.
Loop and output an entire year
JewishCalendar jc = new JewishCalendar(5773, JewishDate.TISHREI, 1);
jc.setInIsrael(false); // false is the default and is set here only for clarity. Set to true for Israel
HebrewDateFormatter hdf = new HebrewDateFormatter();
hdf.setHebrewFormat(true);
HebrewDateFormatter hdfTransliterated = new HebrewDateFormatter();
while (jc.getJewishYear() == 5773) {
String hebrewOutput = hdf.format(jc);
String transliteratedOutput = hdfTransliterated.format(jc);
if (jc.getDayOfWeek() == 7 && jc.getParshah() != JewishCalendar.Parshah.NONE) { // Shabbos with a parsha
hebrewOutput += " - " + hdf.formatParshah(jc);
transliteratedOutput += " - " + hdfTransliterated.formatParshah(jc);
}
if (jc.isYomTov() || jc.isTaanis()) { // includes Chanukah
hebrewOutput += ", " + hdf.formatYomTov(jc);
transliteratedOutput += ", " + hdfTransliterated.formatYomTov(jc);
}
if (jc.isRoshChodesh()) {
hebrewOutput += ", " + hdf.formatRoshChodesh(jc);
transliteratedOutput += ", " + hdfTransliterated.formatRoshChodesh(jc);
}
if (jc.getDayOfOmer() > 0) {
hebrewOutput += ", " + hdf.formatOmer(jc);
transliteratedOutput += ", " + hdfTransliterated.formatOmer(jc);
}
System.out.println(transliteratedOutput + " - " + hebrewOutput);
jc.plusDays(1);
}Output (most days removed for brevity):
1 Tishrei, 5773, Rosh Hashana - א׳ תשרי תשע״ג, ראש השנה
2 Tishrei, 5773, Rosh Hashana - ב׳ תשרי תשע״ג, ראש השנה
3 Tishrei, 5773, Fast of Gedalyah - ג׳ תשרי תשע״ג, צום גדליה
4 Tishrei, 5773 - ד׳ תשרי תשע״ג
...
6 Tishrei, 5773 - Vayeilech - ו׳ תשרי תשע״ג - וילך
...
10 Tishrei, 5773, Yom Kippur - י׳ תשרי תשע״ג, יום כיפור
...
15 Tishrei, 5773, Succos - ט״ו תשרי תשע״ג, סוכות
16 Tishrei, 5773, Succos - ט״ז תשרי תשע״ג, סוכות
17 Tishrei, 5773, Chol Hamoed Succos - י״ז תשרי תשע״ג, חול המועד סוכות
18 Tishrei, 5773, Chol Hamoed Succos - י״ח תשרי תשע״ג, חול המועד סוכות
19 Tishrei, 5773, Chol Hamoed Succos - י״ט תשרי תשע״ג, חול המועד סוכות
20 Tishrei, 5773, Chol Hamoed Succos - כ׳ תשרי תשע״ג, חול המועד סוכות
21 Tishrei, 5773, Hoshana Rabbah - כ״א תשרי תשע״ג, הושענא רבה
22 Tishrei, 5773, Shemini Atzeres - כ״ב תשרי תשע״ג, שמיני עצרת
23 Tishrei, 5773, Simchas Torah - כ״ג תשרי תשע״ג, שמחת תורה
...
30 Tishrei, 5773, Rosh Chodesh Cheshvan - ל׳ תשרי תשע״ג, ראש חודש חשון
1 Cheshvan, 5773, Rosh Chodesh Cheshvan - א׳ חשון תשע״ג, ראש חודש חשון
...
25 Kislev, 5773, Chanukah 1 - כ״ה כסלו תשע״ג, א׳ חנוכה
26 Kislev, 5773, Chanukah 2 - כ״ו כסלו תשע״ג, ב׳ חנוכה
27 Kislev, 5773, Chanukah 3 - כ״ז כסלו תשע״ג, ג׳ חנוכה
28 Kislev, 5773, Chanukah 4 - כ״ח כסלו תשע״ג, ד׳ חנוכה
29 Kislev, 5773, Chanukah 5 - כ״ט כסלו תשע״ג, ה׳ חנוכה
1 Teves, 5773, Chanukah 6, Rosh Chodesh Teves - א׳ טבת תשע״ג, ו׳ חנוכה, ראש חודש טבת
2 Teves, 5773 - Miketz, Chanukah 7 - ב׳ טבת תשע״ג - מקץ, ז׳ חנוכה
3 Teves, 5773, Chanukah 8 - ג׳ טבת תשע״ג, ח׳ חנוכה
...
10 Teves, 5773, Tenth of Teves - י׳ טבת תשע״ג, עשרה בטבת
...
15 Shevat, 5773 - Beshalach, Tu B'Shvat - ט״ו שבט תשע״ג - בשלח, ט״ו בשבט
...
21 Shevat, 5773 - כ״א שבט תשע״ג
...
11 Adar, 5773, Fast of Esther - י״א אדר תשע״ג, תענית אסתר
...
14 Adar, 5773, Purim - י״ד אדר תשע״ג, פורים
15 Adar, 5773, Shushan Purim - ט״ו אדר תשע״ג, שושן פורים
...
27 Adar, 5773 - Vayakhel Pekudei - כ״ז אדר תשע״ג - ויקהל פקודי
...
15 Nissan, 5773, Pesach - ט״ו ניסן תשע״ג, פסח
16 Nissan, 5773, Pesach, Omer 1 - ט״ז ניסן תשע״ג, פסח, א׳ בעומר
17 Nissan, 5773, Chol Hamoed Pesach, Omer 2 - י״ז ניסן תשע״ג, חול המועד פסח, ב׳ בעומר
18 Nissan, 5773, Chol Hamoed Pesach, Omer 3 - י״ח ניסן תשע״ג, חול המועד פסח, ג׳ בעומר
19 Nissan, 5773, Chol Hamoed Pesach, Omer 4 - י״ט ניסן תשע״ג, חול המועד פסח, ד׳ בעומר
20 Nissan, 5773, Chol Hamoed Pesach, Omer 5 - כ׳ ניסן תשע״ג, חול המועד פסח, ה׳ בעומר
21 Nissan, 5773, Pesach, Omer 6 - כ״א ניסן תשע״ג, פסח, ו׳ בעומר
22 Nissan, 5773, Pesach, Omer 7 - כ״ב ניסן תשע״ג, פסח, ז׳ בעומר
23 Nissan, 5773, Omer 8 - כ״ג ניסן תשע״ג, ח׳ בעומר
...
26 Nissan, 5773 - Shmini, Omer 11 - כ״ו ניסן תשע״ג - שמיני, י״א בעומר
...
6 Sivan, 5773, Shavuos - ו׳ סיון תשע״ג, שבועות
7 Sivan, 5773, Shavuos - ז׳ סיון תשע״ג, שבועות
...
17 Tammuz, 5773, Seventeenth of Tammuz - י״ז תמוז תשע״ג, שבעה עשר בתמוז
...
9 Av, 5773, Tishah B'Av - ט׳ אב תשע״ג, תשעה באב
...
15 Av, 5773, Tu B'Av - ט״ו אב תשע״ג, ט״ו באב
...
The Zmanim API version 1.3.0 was released on March 4th, 2013 – כ״א אדר תשע״ג. Various changes in the new release vs. the previous version 1.2.1 that was released in May 2010 can be seen below. This release includes beta support for Jewish Calendar calculations as well as a number of updated zmanim and refactored code. The Jewish Calendar support in the Zmanim API is based on
The 
