Skip to content

A java Library that converts Gregorian to Jalali (or Jalali to Gregorian)

License

Notifications You must be signed in to change notification settings

eloyzone/jalali-calendar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central

jalali-calendar

A java Library that converts Gregorian to Jalali (or Jalali to Gregorian) For Gregorian date, it uses Java8's date and for Jalali date has its own codes which are inspired from Java8.

How can I use jalali-calendar?

You can download source code directly to your existing projects and then use it or you can download it from maven or other repositories.

Maven

How to Include In Maven Project

<dependency>
    <groupId>com.github.eloyzone</groupId>
    <artifactId>jalali-calendar</artifactId>
    <version>1.0.0</version>
</dependency>

Some Basic Codes:

// Create an object of DateConverter, its the main class that converts calendars
DateConverter dateConverter = new DateConverter();

// Convert Jalali date to Gregorian
LocalDate localdate1 = dateConverter.jalaliToGregorian(1370, 11, 28);
LocalDate localdate2 = dateConverter.jalaliToGregorian(1386, MonthPersian.ESFAND, 29);

// Convert Gregorian date to Jalali
JalaliDate jalaliDate1 = dateConverter.gregorianToJalali(1992, 2, 17);
JalaliDate jalaliDate2 = dateConverter.gregorianToJalali(2019, 3, 20);

// checking for leapyer of Jalali Date
boolean leapyer1 = new JalaliDate(1370, 11, 28).isLeapYear());
boolean leapyer2 = dateConverter.gregorianToJalali(1992, 2, 17).isLeapYear();

// Day of week
String dayOfWeek1 = new JalaliDate(1370, 11, 28).getDayOfWeek().getStringInPersian(); // Doshanbe
String dayOfWeek2 = new JalaliDate(1370, 11, 28).getDayOfWeek().getStringInEnglish(); // دوشنبه

Date Formatter:

For Gregorian date no formatter is provided by this lib as Java8 has got a good formatter but for JalaliDate You can use JalaliDateFormatter class like below codes The Jalai's formatter not only provide English but also Persian. Its default form is English.

DateConverter dateConverter = new DateConverter();
JalaliDate jalaliDate = dateConverter.gregorianToJalali(1992, Month.FEBRUARY, 17);
String result = jalaliDate.format(new JalaliDateFormatter("yyyy/mm/dd", JalaliDateFormatter.FORMAT_IN_PERSIAN);
// result will be: ١٣٧٠/١١/٢٨

String result2 = jalaliDate.format(new JalaliDateFormatter("yyyy- M dd", JalaliDateFormatter.FORMAT_IN_PERSIAN);
// result2 will be: ٢٨ بهمن -١٣٧٠

For more options it's highly recomended to see unit tests of this library, it's covered most possible options and can be good guide for you.

Releases

No releases published

Packages

No packages published

Languages