将gregorian转换为hijri日期 [英] converting gregorian to hijri date

查看:142
本文介绍了将gregorian转换为hijri日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将格里高利语转换为伊斯兰教日期,我需要一个java类来进行转换。我想以格式yyyy / mm / dd作为字符串给它一个格里高利日期,并以相同的格式给我Hijri日期。可以帮助我吗?

I want to convert from Gregorian to Hijri(Islamic) date and I need a java class for this converting. I want to give it an Gregorian date in format of "yyyy/mm/dd" as string and it give me the Hijri date in the same format. can anyone help me?

推荐答案

首先,将转换部分与格式化/解析部分分开。您稍后可以轻松处理这些问题 - 而且有关堆栈溢出问题的批次。

Firstly, separate out the conversion part from the formatting/parsing part. You can deal with those easily later - and there are lots of questions on Stack Overflow about that.

我个人使用 Joda Time ,这通常会使生活更简单。例如:

Personally I'd use Joda Time, which typically makes life much simpler. For example:

import org.joda.time.Chronology;
import org.joda.time.LocalDate;
import org.joda.time.chrono.IslamicChronology;
import org.joda.time.chrono.ISOChronology;

public class Test {
    public static void main(String[] args) throws Exception {
        Chronology iso = ISOChronology.getInstanceUTC();
        Chronology hijri = IslamicChronology.getInstanceUTC();

        LocalDate todayIso = new LocalDate(2013, 3, 31, iso);
        LocalDate todayHijri = new LocalDate(todayIso.toDateTimeAtStartOfDay(),
                                             hijri);
        System.out.println(todayHijri); // 1434-05-19
    }
} 

(感觉像应该有一个更清洁的方式在时间顺序之间转换日期,但是我马上找不到。)

(It feels like there should be a cleaner way of converting dates between chronologies, but I couldn't find one immediately.)

这篇关于将gregorian转换为hijri日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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