成对 (Java):Hijri 到 Gregorian 转换 inasikarat?
JodaTime (Java): Hijri to Gregorian conversion inaccurate?
我目前正在实现一个日历转换器,给定回历输入日期和时间,使用 JodaTime
库输出相应的公历日期和时间。但是,对应的公历时间并不准确。无论我在同一天输入什么回历时间,得到的公历日期都是一样的。这似乎很奇怪,考虑到每个回历日跨越两个公历日,从日落到日落,如本回答 (https://islam.stackexchange.com/questions/71850/can-a-day-in-the-gregorian-calendar-correspond-to-two-different-days-in-the-isla) 中所述。
例如,下面是从回历日期时间(当前日期,可以指定一天中的不同时间)转换为相应的公历日期时间的代码:
Chronology iso = ISOChronology.getInstanceUTC();
Chronology hijri = IslamicChronology.getInstanceUTC();
DateTime currentDate = DateTime.now();
int year = currentDate.getYear();
int month = currentDate.getMonthOfYear();
int day = currentDate.getDayOfMonth();
int customHr = 23;
int customMin = 59;
int customSec = 59;
DateTime todayIso = new DateTime(year, month, day, customHr, customMin, customSec, 0, iso);
LocalDateTime todayHijri = new LocalDateTime(todayIso, hijri);
System.out.println(todayHijri.toString());
结果如下:
Hijri DateTime Input: 8/24/2021 at final second (23:59)
Gregorian DateTime Output: 1443-01-15T23:59:59.000
Hijri DateTime Input: 8/24/2021 at first second (0:01)
Gregorian DateTime Output: 1443-01-15T00:00:01.000
但是,当我 运行 这段从公历日期时间转换为回历日期时间的代码时:
Chronology hijri = IslamicChronology.getInstanceUTC();
int customHour = 0;
int customMin = 0;
int customSec = 1;
DateTime todayIso = new DateTime(2021, 8, 24, customHour, customMin, customSec);
LocalDateTime todayHijri = new LocalDateTime(todayIso, hijri);
System.out.println(todayHijri);
这些是我使用公历到回历转换的输出作为输入得到的结果。如您所见,在回历到公历的转换中,输出的回历日期时间与输入的回历日期时间不同,这意味着有问题。
Gregorian DateTime Input: 8-24-2021 at 0:01
Hijri DateTime Output: 1443-01-15T07:00:01.000
Gregorian DateTime Input: 8-24-2021 at 23:59:59
Hijri DateTime Output: 1443-01-16T06:59:59.000
发件人:http://joda-time.sourceforge.net/cal_islamic.html
A day in the Islamic calendar begins at sunset on the previous 'day'. Joda-Time does not model this, thus times and date rollover follow standard ISO definitions, in other words starting at midnight
有关选项,请参阅:。
我目前正在实现一个日历转换器,给定回历输入日期和时间,使用 JodaTime
库输出相应的公历日期和时间。但是,对应的公历时间并不准确。无论我在同一天输入什么回历时间,得到的公历日期都是一样的。这似乎很奇怪,考虑到每个回历日跨越两个公历日,从日落到日落,如本回答 (https://islam.stackexchange.com/questions/71850/can-a-day-in-the-gregorian-calendar-correspond-to-two-different-days-in-the-isla) 中所述。
例如,下面是从回历日期时间(当前日期,可以指定一天中的不同时间)转换为相应的公历日期时间的代码:
Chronology iso = ISOChronology.getInstanceUTC();
Chronology hijri = IslamicChronology.getInstanceUTC();
DateTime currentDate = DateTime.now();
int year = currentDate.getYear();
int month = currentDate.getMonthOfYear();
int day = currentDate.getDayOfMonth();
int customHr = 23;
int customMin = 59;
int customSec = 59;
DateTime todayIso = new DateTime(year, month, day, customHr, customMin, customSec, 0, iso);
LocalDateTime todayHijri = new LocalDateTime(todayIso, hijri);
System.out.println(todayHijri.toString());
结果如下:
Hijri DateTime Input: 8/24/2021 at final second (23:59)
Gregorian DateTime Output: 1443-01-15T23:59:59.000
Hijri DateTime Input: 8/24/2021 at first second (0:01)
Gregorian DateTime Output: 1443-01-15T00:00:01.000
但是,当我 运行 这段从公历日期时间转换为回历日期时间的代码时:
Chronology hijri = IslamicChronology.getInstanceUTC();
int customHour = 0;
int customMin = 0;
int customSec = 1;
DateTime todayIso = new DateTime(2021, 8, 24, customHour, customMin, customSec);
LocalDateTime todayHijri = new LocalDateTime(todayIso, hijri);
System.out.println(todayHijri);
这些是我使用公历到回历转换的输出作为输入得到的结果。如您所见,在回历到公历的转换中,输出的回历日期时间与输入的回历日期时间不同,这意味着有问题。
Gregorian DateTime Input: 8-24-2021 at 0:01
Hijri DateTime Output: 1443-01-15T07:00:01.000
Gregorian DateTime Input: 8-24-2021 at 23:59:59
Hijri DateTime Output: 1443-01-16T06:59:59.000
发件人:http://joda-time.sourceforge.net/cal_islamic.html
A day in the Islamic calendar begins at sunset on the previous 'day'. Joda-Time does not model this, thus times and date rollover follow standard ISO definitions, in other words starting at midnight
有关选项,请参阅: