是否有回历日期可以转换为格鲁吉亚日期转换,反之亦然? [英] Is there a Hijri Date to Georgian Date Conv and vice versa, which is reliable?

查看:116
本文介绍了是否有回历日期可以转换为格鲁吉亚日期转换,反之亦然?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个可以为我提供所需工具的图书馆,以计算从现在起到特定日期的天数,并可以用来确定我是否处于特定时间段(例如。Muharram +-5days

I am looking for a Library that can give me the needed tools, to calculate for example how many days it is from now, to a specific Date AND that I can use to determine whether I am in a specific time period (eg. Muharram +- 5days) or not

我一直在寻找10个小时以上,而我发现的最好的东西是 HijrahDate库 java.time.chrono .HijrahDate和一个叫 Joda Date的东西,我很难用。

I have been looking for over 10hours now, and the best things I found were the "HijrahDate" library "java.time.chrono.HijrahDate" and something called "Joda Date", which I had difficulties to use.

如果有人可以帮助我,将不胜感激。

If anyone can help me with that, it would be much appreciated.

推荐答案

您要使用哪种回历日历?

如果您选择沙特阿拉伯的官方日历,则基于 java.time.HijrahDate 可以工作。但是此类至少需要Android上的API级别26。示例:

If you opt for the official calendar of Saudi-Arabia then the solution based on java.time.HijrahDate would work. But this class requires at least API level 26 on Android. Example:

HijrahDate hd1 = HijrahDate.now();
HijrahDate hd2 = HijrahDate.from(LocalDate.of(2020, 5, 1));
long days = ChronoUnit.DAYS.between(hd1, hd2);

还有比较方法,例如 isAfter() isBefore()从接口 ChronoLocalDate 和标准plus()方法继承来确定您的日期

There are also comparison methods like isAfter() or isBefore() inherited from the interface ChronoLocalDate and standard plus()-methods in order to determine if your date is in a specific time period.

java.time 的后台:

Backport of java.time:

还有一个名为 ThreetenABP Android版本。但是请注意一个陷阱,它的 HijrahDate 的实现是不同的,并且不使用沙特阿拉伯的日历(因此您必须容忍日期转换中的差异)。

There is also a backport called ThreetenABP for lower Android-versions. But be aware of the pitfall that its implementation of HijrahDate is different and does NOT use the calendar of Saudi-Arabia (so you have to tolerate differences in date conversion).

关于Joda-Time:

如果您选择该(相当陈旧)的库那么您应该选择适用于android 的库版本。但是,它也不支持沙特阿拉伯的日历,但提供了其他四个不同的版本。您需要指定算法 leap年模式

If you opt for that (rather outdated) library then you should choose the library version adapted for android. However, it does not support the calendar of Saudi-Arabia, too, but offers four different other variations. You would need to specify the algorithmic leap year pattern.

ICU4J(嵌入Android):

其类 IslamicCalendar 提供的样式类似于<$的旧日历类c $ c> java.util.Calendar 以及包括沙特阿拉伯在内的多个变体。最低要求的API级别为24。

Its class IslamicCalendar offers a style similar to old calendar classes java.util.Calendar and also several variants including that of Saudi-Arabia. The minimum required API level is 24.

Time4A:

由我自己编写的库(如适用于Android的Time4J的适配)。它提供了 HijriCalendar 类,其中包括Joda-变体,但还包括沙特阿拉伯的日历(变体ummalqura)。它提供了所有必需的功能,例如日期算术(通过plus()-或minus()-方法),日期比较(通过isAfter()等)。示例:

That is a library written by myself (as adaptation of Time4J for Android). It offers the class HijriCalendar with several variations including the Joda-variants but also including the calendar of Saudi-Arabia (variant ummalqura). It offers all needed features like date arithmetic (by plus()- or minus()-method), date comparison (by isAfter() etc.). Example:

String variant = HijriCalendar.VARIANT_UMALQURA;
StartOfDay startOfDay = StartOfDay.definedBy(SolarTime.ofMecca().sunset());
HijriCalendar today = HijriCalendar.nowInSystemTime(variant, startOfDay);
HijriCalendar hcal = // gregorian to Hijri conversion
    PlainDate.of(2020, 5, 1).transform(HijriCalendar.class, variant);
long days = CalendarDays.between(today, hcal).getAmount();

其他图书馆不支持诸如日落之类的功能。您的穆哈拉姆语(Muharram)示例-5天请求可能类似于:

Features like sunset as start of day are not supported by other libraries. Example for your Muharram +- 5days-request might look like:

CalendarDays tolerance = CalendarDays.of(5);
HijriCalendar htemp = today.with(HijriCalendar.MONTH_OF_YEAR, HijriMonth.MUHARRAM);
HijriCalendar h1 = htemp.with(HijriCalendar.DAY_OF_MONTH.minimized()).minus(tolerance);
HijriCalendar h2 = htemp.with(HijriCalendar.DAY_OF_MONTH.maximized()).plus(tolerance);
boolean inTimePeriod = !(today.isBefore(h1) || today.isAfter(h2));

这篇关于是否有回历日期可以转换为格鲁吉亚日期转换,反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆