Reputation: 598
I want to convert Hijri date to Gregorian date! I've searched, but unfortunately I found a java class for converting Gregorian to Hijri. I need the opposite.
HijriCalendar.java: https://gist.github.com/fatfingers/6492017
Upvotes: 2
Views: 7486
Reputation: 339
Try this:
Kotlin:
import java.time.LocalDate
import java.time.chrono.HijrahChronology
import java.time.chrono.HijrahDate
@RequiresApi(Build.VERSION_CODES.O)
fun convertHijriToGregorian(hijriYear: Int, hijriMonth: Int, hijriDay: Int): LocalDate {
val hijriDate = HijrahDate.of(hijriYear, hijriMonth, hijriDay)
return LocalDate.from(hijriDate)
}
And use it like this:
@RequiresApi(Build.VERSION_CODES.O)
fun main() {
val hijriYear = 1443
val hijriMonth = 8
val hijriDay = 5
val gregorianDate = convertHijriToGregorian(hijriYear, hijriMonth, hijriDay)
println("Gregorian date: $gregorianDate")
}
Java:
import java.time.LocalDate;
import java.time.chrono.HijrahChronology;
import java.time.chrono.HijrahDate;
public class Main {
public static void main(String[] args) {
int hijriYear = 1443;
int hijriMonth = 8;
int hijriDay = 5;
LocalDate gregorianDate = convertHijriToGregorian(hijriYear, hijriMonth, hijriDay);
System.out.println("Gregorian date: " + gregorianDate);
}
public static LocalDate convertHijriToGregorian(int hijriYear, int hijriMonth, int hijriDay) {
HijrahDate hijriDate = HijrahDate.of(HijrahChronology.INSTANCE, hijriYear, hijriMonth, hijriDay);
return LocalDate.from(hijriDate);
}
}
Upvotes: 1
Reputation: 1
General Method for Converting Hijri Dates to Gregorian dates
The problem: I have a long list of Hijri dates I wanted to convert to a list of Gregorian dates. Solution: Here are the steps, I used to convert my list:
Upvotes: 0
Reputation: 11
The formula to convert Muslim (M) dates to CE is:
CE = ((M x 970224)/1000000)+ 621.5774 = CE.nnn
then 0.nnn x 365
= day of the CE year M year began.
From that you can determine the day you are looking for from the Muslim month chart:
Years run in 30 year cycles.
Each cycle starts on 15 June. The 2nd, 5th, 7th, 10th, 13th, 16th, 18th, 21st, 24th 26th and 29th are leap years.
One cycle = 10, 631 days.
Hope this helps. I also have the formula for converting CE dates to Muslim dates.
Upvotes: 1