I know this question was asked many times but I didn't find the correct way. I have a String
date like 01-08-1994. And I want to convert it to a Hijri
date.
using IslamicCalendar
.
Asked
Active
Viewed 3,927 times
2

Phantômaxx
- 37,901
- 21
- 84
- 115

Ahmed
- 259
- 3
- 14
-
Possible duplicate of [Intellij - Unable to use newer Java 8 classes - Error : "Usage of API documented as @since 1.6+.."](https://stackoverflow.com/questions/37787079/intellij-unable-to-use-newer-java-8-classes-error-usage-of-api-documented) – Eselfar Jun 27 '18 at 09:20
-
No . I edited my question . – Ahmed Jun 27 '18 at 09:26
-
1So what have you tried so far? – Eselfar Jun 27 '18 at 09:28
-
I tried to read the documentation of `IslamicCalendar ` but I couldn't able to know exactly how to convert my `Gregorian` date to `Hijri` . So please delete your comment which say my qustion is dublicated and I see it isn't . – Ahmed Jun 27 '18 at 09:31
2 Answers
5
java.time
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-uuuu");
String gregorianString = "01-08-1994";
LocalDate gregorianDate = LocalDate.parse(gregorianString, dateFormatter);
HijrahDate islamicDate = HijrahDate.from(gregorianDate);
System.out.println("Islamic date: " + islamicDate);
This prints:
Islamic date: Hijrah-umalqura AH 1415-02-23
I assumed your string meant 1 August 1994. If January 8 was intended instead, swap dd
and MM
in the format pattern string in the code.
ThreeTenABP
To use the above on Android below API level 26 you will need to add the ThreeTenABP library to your project first.
I haven’t got the experience, but I have been told that the dependencies are: compile group: 'org.threeten', name: 'threetenbp', version: '1.3.3', classifier: 'no-tzdb'
. See the links below for more details. I have tested the code above with the backport, only not the Android edition of it.
Links
- Oracle tutorial: Date Time explaining how to use
java.time
. - Java Specification Request (JSR) 310, where
java.time
was first described. - ThreeTen Backport project, the backport of
java.time
to Java 6 and 7 (ThreeTen for JSR-310). - ThreeTenABP, Android edition of ThreeTen Backport
- Question: How to use ThreeTenABP in Android Project, with a very thorough explanation.
- Comment about dependencies for ThreeTenABP

Basil Bourque
- 303,325
- 100
- 852
- 1,154

Ole V.V.
- 81,772
- 15
- 137
- 161