I suggest you com.ibm.icu
. It contains an awesome library for Jalali calendar.
If your project is a maven based, you can use the following dependency:
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>59.1</version>
</dependency>
And this is a sample use of Persian calendar:
//configuration
ULocale locale = new ULocale("@calendar=persian");
Calendar calendar = Calendar.getInstance(locale);
calendar.setFirstDayOfWeek(7); //Make Saturdays first day of the week.
//usage
calendar.setTime(new Date());
int year = calendar.get(Calendar.YEAR);
int weekOfYear = (calendar.get(Calendar.YEAR_WOY) == year)? calendar.get(Calendar.WEEK_OF_YEAR) : 53;
int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);
It is important to know Calendar
and ULocale
are from com.ibm.icu.util.Calendar
and com.ibm.icu.util.ULocale
. NOT java.util
.
If you have any problem in understanding the code, do not hesitate to ask.