Reputation: 125
I want to convert date from Persian calendar to Gregorian Calendar. For this, I use ICU4J library (version 65.1). The problem is that this library gives wrong output for some dates.
Here is my code:
ULocale locale = new ULocale("fa_IR@calendar=persian");
GregorianCalendar gregoriancal = new GregorianCalendar();
Calendar persiancal = Calendar.getInstance(locale);
// year month day
persiancal.set(1398, 11, 16);
gregoriancal.setTime(persiancal.getTime());
String day = gregoriancal.get(Calendar.DATE) + "";
System.out.println(day);
----------------------------------------
output: 6
this date in persian calendar ( 1398/11/16 ) equls to 2020-02-05 Wednesday February in Gregorian Calendar
but it gives me 6 as output ( while it should give 5 )
is there something wrong with my code that results in a wrong output??
Upvotes: 2
Views: 714
Reputation: 109547
After looking at the javadoc passing the ULocale
should do the trick to put the GregorianCalendar in the correct time zone:
com.ibm.icu.util.GregorianCalendar gregoriancal =
new com.ibm.icu.util.GregorianCalendar(locale);
I think the month may be 0-based as in java.util.Calendar.
persiancal.set(1398, 11-1, 16);
Upvotes: 1