I am using the class shown in this Question to convert Jalali (shamsi) date to Georgian.
And with the below command, I turn the Hijri date into Georgian
Date dt = JalaliCalendar.getGregorianDate("1397/01/14");
Toast.makeText(getApplicationContext(), dt.toString(), Toast.LENGTH_LONG).show();
I want to display the result as follows : 2018/04/03
Caveat: I know nothing about either Jalali calendar nor Hijri calendar except for two minutes spent scanning the Wikipedia pages. But I might be able to help you get part way to a solution.
java.time
You are using troublesome old date-time classes that were supplanted years ago by the java.time classes.
The java.time classes come bundled with a
HijrahChronology
implementation ofChronology
.Suggestion: Implement
java.time.chrono.Chronology
I do not see any implementation of
Chronology
for the Jalali calendar either bundled with java.time nor in the ThreeTen-Extra project that does provide other chronologies.I imagine it might be ideal if someone did contribute such an implementation. Perhaps such an implementation could be written by following the example of the
HijrahChronology
bundled with Java.HijrahChronology.java
HijrahDate.java
HijrahEra.java
hijrah-config-islamic-umalqura.properties
Hijri (not Jalali)
Here is my ignorant attempt at using the
HijrahDate
class.That seems to be correct for Hijri Calendar as shown on this Iranian Calendar Converter page.
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as
java.util.Date
,Calendar
, &SimpleDateFormat
.The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for
java.sql.*
classes.Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as
Interval
,YearWeek
,YearQuarter
, and more.Try to use SimpleDateFormatter as follows:
Using my library Time4J (or Time4A on Android) enables following short solution out of the box:
No need to implement your own calendar chronology (which is generally a complex task). If you want to get the result with slashes instead of ISO-format then just use another formatter by: