This library is an implementation of Solar Hijri calendar (also known as Jalali calendar or Persian calendar). It is an immutable and thread-safe implementation of Persian calendar system, and can be used in multi-threaded programs.
As Java does not support Persian calendar, this library can be used in the applications that need Persian calendar system. Purpose of this library is to provide an immutable and easy API (that is similar to JDK 8 date and time API) for Persian calendar system. This class has been implemented the same as internal JDK calendars such as JapaneseDate.
Include the following to your dependency list:
<dependency>
<groupId>com.github.mfathi91</groupId>
<artifactId>persian-date-time</artifactId>
<version>4.0.0</version>
</dependency>
One can get an instance of PersianDate for the present date:
PersianDate today = PersianDate.now();
To get an instance of PersianDate for a desired date:
PersianDate persianDate1 = PersianDate.of(1396, 7, 15);
PersianDate persianDate2 = PersianDate.of(1396, PersianMonth.MEHR, 15);
It is possible to easily convert Persian date to other calendar systems dates, such as Gregorian date:
PersianDate persianDate = PersianDate.of(1397, 5, 11);
LocalDate gregDate1 = persianDate.toGregorian(); // => '2018-08-02'
// another possible approach to convert
LocalDate gregDate2 = LocalDate.from(persianDate); // => '2018-08-02'
Converting other calendar system dates, such as Gregorian date would be like the following:
LocalDate gregDate = LocalDate.of(2015, 4, 17);
PersianDate persianDate = PersianDate.fromGregorian(gregDate); // => '1394/01/28'
The conversion algorithm from Solar Hijri calendar to Gregorian calendar and vice versa, is adopted from here.
It is possible to format an instance of PersianDate using DateTimeFormatter class:
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
dtf.format(PersianDate.now()); // => e.g. '1396/05/10'
// another possible approach to format
PersianDate.now().format(dtf); // => e.g. '1396/05/10'
This version of Persian Date Time requires:
- Java SE 8
This library is released under MIT license.