在Java中将Jalali日历转换为格鲁吉亚 [英] Convert Jalali calendar to Georgian in java

查看:81
本文介绍了在Java中将Jalali日历转换为格鲁吉亚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用类






关于 java.time



java.time 框架是bui进入Java 8及更高版本。这些类取代了麻烦的旧旧版日期时间类,例如 java.util.Date 日历 ,& SimpleDateFormat



Joda-Time 项目,现在处于维护模式 ,建议迁移到 java.time 类。



要了解更多信息,请参见 Oracle教程 。并在Stack Overflow中搜索许多示例和说明。规范为 JSR 310



您可以直接与数据库交换 java.time 对象。使用符合 JDBC驱动程序 / jeps / 170 rel = nofollow noreferrer> JDBC 4.2 或更高版本。不需要字符串,不需要 java.sql。* 类。



在哪里获取java.time类?





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?

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屋!

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