I'm developing a Java App and I have a timeStamp
(in long
). I can easily use this code to change it to a Gregorian date:
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timeStamp);
But I need to have the date in Jalali Calendar. I searched but didn't found any good library. Do you know a reliable and good library for converting (or creating dates in Jalali format from timeStamp
)? I don't need an implementation or an algorithm, cause this issue is too buggy and has a lot of rules, I need a reliable solution
There is a good library on github which has a very simple API and it has a lot of capabilities and it also it available on mavenCentral :
https://github.com/razeghi71/JalaliCalendar
I have developed my own Persian (jalali) calendar in Java within my library Time4J. The implementation deploys the algorithm of Borkowski (valid at least until gregorian year 2129 - no 2025-bug).
Solution for the concrete problem of OP:
Of course, the calendar offers more features like date arithmetic (adding days or months, calculating the delta in days, months etc.) or field/element-manipulations (easy going to the last day of month etc).
Side notes about other libraries proposed here so far:
The libraries amirmehdizadeh/JalaliCalendar as well as ICU4J both use zero-based months. This can be extremely confusing. Non-intuitive example using amirmehdizadeh's library:
About internationalization, I don't think that ICU4J offers more than Time4J on the area of Persian calendar since latter one is based on newest CLDR-version v28, too. Time4J actually supports about 25 languages for Persian months and eras (including Farsi and Pashto).
You can use JalCal that Jalali(Persian) Calender Convertor in Java:
1. Jalali to Gregorian
2. Gregorian to Jalali
You can find a graphical java-based Jalali calendar called persain-calendar. Here is a screenshot of Persian-calendar.
Take a look on this: https://github.com/amirmehdizadeh/JalaliCalendar
The code looks nice, maven based project, a lot of unit tests.
For better localization and language support, it is often convenient to use the ICU (International Components for Unicode) library from IBM.
The APIs are similar to the standard Java APIs, but add additional support for localization and internationalization (e.g. time and calendar issues, sorting, formatting rules and a regex implementation with proper Unicode support).
To create a Persian calendar and output the formatted date in Farsi, you would e.g. do something like this:
This will output:
چهارشنبه ۱۰ اردیبهشت ۱۳۹۳ ه.ش.