4

we hear those days that java8 will includes Umalqura calendar APi which manages Hijri Date .

Where to find a sample that convert Date To Hijri ?

Indeed , i find this code :

HijrahDate hdate = HijrahChronology.INSTANCE.date(LocalDate.of(2014, Month.JANUARY, 9));

However , i cannot set one INPUT (java.util.Date )instead of 3 INPUTS (YEAR,MONTH ,DATE)

doelleri
  • 19,232
  • 5
  • 61
  • 65
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254

1 Answers1

9

You can convert from a LocalDate - how you get that is up to you. For example:

// Avoid using java.util.Date unless you really have to.
// Stick to java.time.* if possible
Date date = ...; 
Instant instant = Instant.ofEpochMilli(date.getTime());

// Pick the time zone you actually want here...
LocalDate localDate = instant.atZone(ZoneId.of("UTC")).toLocalDate();  

HijrahDate hdate = HijrahChronology.INSTANCE.date(instant);
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • ≫ java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: EpochDay at java.time.Instant.getLong(Instant.java:603) at java.time.chrono.HijrahChronology.date(HijrahChronology.java:523) at java.time.chrono.HijrahChronology.date(HijrahChronology.java:217) – Abdennour TOUMI Nov 25 '14 at 07:06
  • @عبدالنورالتومي: Interesting - try converting to a `LocalDate` first. I'll do that too :) – Jon Skeet Nov 25 '14 at 07:09