无法获得正确的当前伊斯兰日期 [英] Can't get correct current islamic date
问题描述
我正在使用joda时间在沙特阿拉伯中获取当前的伊斯兰日期,如同他们的网站:
i am using joda time to get current islamic date in Saudi Arabia as in their website:
DateTime dtISO = new DateTime(2014, 1, 9, 0, 0, 0, 0);
DateTime dtIslamic = dtISO.withChronology(IslamicChronology.getInstance());
上面打印的日期少于实际日期,打印出今天为7但实际为8。
请告知。
above prints the day less than the actual day, it prints that today is 7 but actual is 8. please advise.
更新:
我甚至试过了时区如下:
i even tried it with timezone as follows:
DateTimeZone SAUDI_ARABIA = DateTimeZone.forID("Asia/Riyadh");
DateTime dtISO = new DateTime(2014, 1, 9, 0, 0, 0, 0);
DateTime dtIslamic = dtISO.withChronology(IslamicChronology.getInstance(SAUDI_ARABIA));
但它给出的结果相同。
推荐答案
首先,我尝试了JodaTime的闰年模式。所有四个定义的模式产生相同的结果,即日期Hijrah 1435-03-07。这里是我的测试代码:
First I have experimented with JodaTime's "leap-year-pattern". All four defined patterns yield the same result, namely the date "Hijrah 1435-03-07". Here my test code:
DateTime dtISO = new DateTime(2014, 1, 9, 0, 0, 0, 0);
DateTimeZone tzSAUDI_ARABIA = DateTimeZone.forID("Asia/Riyadh");
DateTime dtIslamic =
dtISO.withChronology(
IslamicChronology.getInstance(
tzSAUDI_ARABIA,
IslamicChronology.LEAP_YEAR_15_BASED));
System.out.println(dtIslamic);
根据网站islamicfinder.org,日期确实应该是:
According to the website islamicfinder.org the date should indeed be:
周四8 Raby` al-awal 1435 AH
Thursday 8 Raby` al-awal 1435 A.H.
或者看:< a href =http://www.ummulqura.org.sa/ =nofollow> http://www.ummulqura.org.sa/
我们必须记住,Joda Time仅支持基于使用特殊闰年模式的算法计算的伊斯兰日历。总而言之,我知道8种这样的模式。 Joda Time定义了其中的四个。 Joda Time不支持的是沙特阿拉伯的官方日历,即Umalqura日历,这是一个基于目击的日历。总结我们可以说:使用Joda Time是沙特阿拉伯的选择。现在该怎么办?
We have to memorize here that Joda Time only supports islamic calendar based on an algorithmic calculation using a special leap year pattern. All in all I know of 8 such patterns. Joda Time defines four of them. What Joda Time does not support is the official calendar of Saudi-Arabia, namely Umalqura calendar which is a sighting based calendar. So as summary we can say: Using Joda Time is no option for Saudi-Arabia. What to do now?
一个选项是使用 com.ibm.icu.util.IslamicCalendar
,因为@PopoFibo有提及。另一个选项是当前正在等待包含Umalqura日历的Java 8,它不一定与IBM版本相同。详细说明:虽然IBM版本仍然基于计算(天文(非真实)或民用),但类 java.time.chrono.HijrahDate
使用了沙特阿拉伯机构KACST提供的数据背景查询表。我相信这个版本远远超过IBM版本,因为在其他日期IBM(这里它的库ICU4J)不一定正确。所以在Java 8中你可以使用:
One option is using com.ibm.icu.util.IslamicCalendar
as @PopoFibo has mentioned. The other option would be currently waiting for Java 8 which contains Umalqura calendar which is not necessary the same as the IBM version. In detail: While the IBM version is still based on calculations (either "astronomical" (not really) or "civil") the class java.time.chrono.HijrahDate
uses a background lookup table with data given by saudi-arabian agency KACST. I would trust this version far more than the IBM version because for other dates IBM (here its library ICU4J) is not necessarily correct. So in Java 8 you could use:
HijrahDate hdate =
HijrahChronology.INSTANCE.date(LocalDate.of(2014, Month.JANUARY, 9));
System.out.println(hdate); // Output: "Hijrah-umalqura AH 1435-03-08"
这篇关于无法获得正确的当前伊斯兰日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!