Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Umalqura calendar in java 8 with java.util.Date

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)

like image 776
Abdennour TOUMI Avatar asked Jan 10 '23 09:01

Abdennour TOUMI


1 Answers

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);
like image 162
Jon Skeet Avatar answered Jan 27 '23 17:01

Jon Skeet