From Hijiri date to Gregorian in java

334 views Asked by At

I have a GUI that have two comboxes and one textfield to enter the user's Hijiri birth date. I want to convert that Hijiri date to a Gregorian one ... every solution I found either a complex one or does not work .. I even checked the Joda-Time - API - Islamic calendar(HijrahChronology) and it does not have any converting methods !!

1

There are 1 answers

0
Basil Bourque On

tl;dr

LocalDate.from(                     // Convert from Hijrah chronology to ISO 8601 chronology.
    HijrahDate.of( 1400 , 2 , 19 )  // Instantiate a recent birthdate using Islamic calendar.
).toString()                        // Generate text representing this ISO date.

1980-01-08

Details

The java.time.chrono package offers a Hijrah chronology, as well as other chronologies.

While I know nothing about the Islamic calendar, it appears to me you can easily convert between ISO 8601 chronology to that Hijrah chronology.

Instantiate in Hijrah chronology.

// Instantiate a recent birth date using Islamic calendar.
HijrahDate hd = HijrahDate.of( 1400 , 2 , 19 );
System.out.println( "hd.toString(): " + hd );

hd.toString(): Hijrah-umalqura AH 1400-02-19

Convert to ISO 8601 chronology.

// Convert from Hijrah chronology to ISO 8601 chronology.
LocalDate ld = LocalDate.from( hd );
System.out.println( "ld.toString(): " + ld );

ld.toString(): 1980-01-08