ライブラリTime4J内で Java で独自のペルシャ (ジャラリ) カレンダーを開発しました。実装はBorkowskiのアルゴリズムを展開します(少なくともグレゴリオ暦 2129 年まで有効 - 2025 年のバグはありません)。
OPの具体的な問題の解決策:
// conversion from jalali to gregorian by constructed input
PersianCalendar jalali = PersianCalendar.of(1394, 11, 5);
// or use a safe enum instead of the month number:
// PersianCalendar jalali = PersianCalendar.of(1394, PersianMonth.BAHMAN, 5);
PlainDate gregorian = jalali.transform(PlainDate.class);
System.out.println(gregorian); // 2016-01-25
// conversion to millis-since-unix (timezone-dependent)
Moment moment1 = gregorian.atStartOfDay().inTimezone(ASIA.TEHRAN);
long millisSinceUnix = TemporalType.MILLIS_SINCE_UNIX.from(moment1);
System.out.println(millisSinceUnix); // 1453667400000L
// conversion of millis-since-unix to jalali (timezone-dependent)
Moment moment2 = TemporalType.MILLIS_SINCE_UNIX.translate(millisSinceUnix);
PlainDate gregorian2 = moment2.toZonalTimestamp(ASIA.TEHRAN).toDate();
System.out.println(gregorian2.transform(PersianCalendar.class)); // AP-1394-11-05
// formatting and parsing in Farsi language using full style
ChronoFormatter<PersianCalendar> f1 =
ChronoFormatter.ofStyle(DisplayMode.FULL, new Locale("fa"), PersianCalendar.axis());
System.out.println(f1.format(jalali)); // ه.ش. ۱۳۹۴ بهمن ۵, دوشنبه
System.out.println(f1.parse("ه.ش. ۱۳۹۴ بهمن ۵, دوشنبه")); // AP-1394-11-05
// formatting in English language using custom pattern
ChronoFormatter<PersianCalendar> f2 =
ChronoFormatter.ofPattern(
"d. MMMM yyyy", PatternType.CLDR, Locale.ENGLISH, PersianCalendar.axis());
System.out.println(f2.format(jalali)); // 5. Bahman 1394
もちろん、カレンダーは日付計算 (日または月の追加、日、月などのデルタの計算) やフィールド/要素操作 (月の最終日に簡単に移動するなど) などのより多くの機能を提供します。
これまでにここで提案された他のライブラリに関する補足事項:
ライブラリamirmehdizadeh /JalaliCalendar とICU4Jはどちらもゼロベースの月を使用します。これは非常に混乱を招く可能性があります。amirmehdizadeh のライブラリを使用した非直感的な例:
YearMonthDate jalali = new YearMonthDate(1394, 10, 5); // 11th month (Bahman)
YearMonthDate gregorian = JalaliCalendar.jalaliToGregorian(jalali);
System.out.println(gregorian); // 2016/0/25 => 1st month (January)
国際化については、ICU4J がペルシャ暦の領域で Time4J を提供しているとは思いません。後者も最新の CLDR バージョン v28 に基づいているからです。Time4J は、ペルシア語の月と時代 (ペルシア語とパシュトー語を含む) について、約 25 の言語を実際にサポートしています。