在Java中将Jalali日历转换为格鲁吉亚 [英] Convert Jalali calendar to Georgian in java
问题描述
我正在使用类
关于 java.time
java.time 框架是bui进入Java 8及更高版本。这些类取代了麻烦的旧旧版日期时间类,例如 java.util.Date
, 日历
,& SimpleDateFormat
。
Joda-Time 项目,现在处于维护模式 ,建议迁移到 java.time 类。
要了解更多信息,请参见 Oracle教程 。并在Stack Overflow中搜索许多示例和说明。规范为 JSR 310 。
您可以直接与数据库交换 java.time 对象。使用符合 java.sql。*
类。
在哪里获取java.time类?
- Java SE 8 , Java SE 9 ,然后是
- 内置。
- 具有捆绑实现的标准Java API的一部分。
- Java 9添加了一些次要功能和修复。
- Java SE 6 和 Java SE 7
- 许多java.time功能都反向移植到Java 6& 7在> ThreeTen-Backport 中。
- Android
- 较新版本的java.time类的Android捆绑实现。
- 对于较早的Android(< 26), ThreeTenABP 项目改编了 ThreeTen-Backport (如上所述)。请参阅 如何使用ThreeTenABP… 。
ThreeTen-Extra 项目使用其他类扩展了java.time。该项目是将来可能向java.time添加内容的试验场。您可能会在这里找到一些有用的类,例如 时间间隔
, YearWeek
, YearQuarter
和更多。
I am using the class shown in this Question to convert Jalali (shamsi) date to Georgian.
And with the below command, I turn the Hijri date into Georgian
Date dt = JalaliCalendar.getGregorianDate("1397/01/14");
Toast.makeText(getApplicationContext(), dt.toString(), Toast.LENGTH_LONG).show();
I want to display the result as follows : 2018/04/03
Caveat: I know nothing about either Jalali calendar nor Hijri calendar except for two minutes spent scanning the Wikipedia pages. But I might be able to help you get part way to a solution.
java.time
You are using troublesome old date-time classes that were supplanted years ago by the java.time classes.
The java.time classes come bundled with a HijrahChronology
implementation of Chronology
.
Suggestion: Implement java.time.chrono.Chronology
I do not see any implementation of Chronology
for the Jalali calendar either bundled with java.time nor in the ThreeTen-Extra project that does provide other chronologies.
I imagine it might be ideal if someone did contribute such an implementation. Perhaps such an implementation could be written by following the example of the HijrahChronology
bundled with Java.
Hijri (not Jalali)
Here is my ignorant attempt at using the HijrahDate
class.
LocalDate ld = LocalDate.of( 2018, Month.APRIL , 3 ) ; // Western calendar, defined in `IsoChronology` class: https://docs.oracle.com/javase/10/docs/api/java/time/chrono/IsoChronology.html
HijrahDate hd = HijrahDate.from( ld ); // Using class java.time.chrono.HijrahChronology https://docs.oracle.com/javase/10/docs/api/java/time/chrono/HijrahChronology.html
ld.toString(): 2018-04-03
hd.toString(): Hijrah-umalqura AH 1439-07-17
That seems to be correct for Hijri Calendar as shown on this Iranian Calendar Converter page.
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.*
classes.
Where to obtain the java.time classes?
- Java SE 8, Java SE 9, and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and Java SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
- Later versions of Android bundle implementations of the java.time classes.
- For earlier Android (<26), the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP….
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.
这篇关于在Java中将Jalali日历转换为格鲁吉亚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!