Hijri to Gregorian date conversion in Java 8

One of the main features released in Java SE 8 is the new date time api (java.time package). It has been a long standing pain for java developers to manipulate dates using the cumbersome Calendar api. Usually developers would go for external date time libraries like JodaTime to get over the issues with the default java Calendar api.

The good news for us in the islamic world is that Java SE 8 includes support for Hijri Calendar (Umm
Alqurra) by default. Date conversions from and to Hirji couldn’t be easier. The code snippet below shows an example on how to do this Java 8.

import java.time.chrono.HijrahChronology;
import java.time.chrono.HijrahDate;
import java.time.chrono.IsoChronology;

* Created by Mohamed on 3/23/2014
public class Main {
    public static void main(String[] args) {
        HijrahDate date = HijrahChronology.INSTANCE.dateNow();

Running this will print on the console the following:

Hijrah-umalqura AH 1435-05-27

How about creating arbitrary Hijri dates let’s say my 10/11/1404 and printing the full month name? as simple as:

  HijrahDate date = HijrahChronology.INSTANCE.date(1404,11,10);

which will show the output:


All of this of course is just scratching the surface of what’s possible with the api. For more check the date and time api documentation here http://docs.oracle.com/javase/tutorial/datetime/index.html


2 thoughts on “Hijri to Gregorian date conversion in Java 8

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s