I want to convert Gregorian (western) date to Persian (Shamsi) date and vice versa for all versions of Android.
Is there any complete and reliable library or algorithm?
I want to convert Gregorian (western) date to Persian (Shamsi) date and vice versa for all versions of Android.
Is there any complete and reliable library or algorithm?
I have developed Android Shamsi datepicker widget with hijri - gerogian- shamsi event view: https://github.com/irshst/ir.shes.calendar
Create the calculateJalaliDate as function like so; and then return the Jalali date in String
I think this java class is easier to use and more reliable. I found it in Iranian forum, Iranians use Jalali Calendar and call it "Shamsi" that means Solar calendar. this is the Java class:
You can easily set the Gregorian Day, Month and Year, then call "getIranianDate()" method to get the date in string format, just like the sample code below:
I hope it helps.
The newest version v3.10-2015g of my library Time4A (an Android adaptation of Time4J) contains support for the Jalali calendar. The library deploys the algorithm of Borkowski (valid until gregorian year 2129). Actually about 25 languages are supported for Persian months and eras (including Farsi and Pashto, based on CLDR-28).
Examples of usage:
Interoperability with java.util.Date on Android
Since Time4A manages its own set of immutable types and is not based on the primary temporal type of Android, I show following bridge:
this method is very exact and simply also support leap years
Explain:
step 1: time today is contain current time
step 2: create two array for gregorian and jalali day in months(g_days_in_month&j_days_in_month)
step 3: create variable for retention difference time between calendars (gy,gm,gd) and variable g_day_no for days of years.
step 4: insert day of month and collect with days.
step 5: convert days of years to jalili years (jy)
at the end : set jalali month from day number, set jalali day from jalali day of month array.
good luck.