dououde4065 2017-11-29 12:34
浏览 15
已采纳

回历日期到戈兰公历

I'm trying to convert a Hijri Date to Gregorian date according to Umm AlQura calendar. I couldn't find much on the Internet (maybe attributing to my lazy attitude). I tried converting the Hijri date to Julian number and then from Julian number to Gregorian date.

However, I just could convert Hijri date to Julian number. I cannot figure out how to convert from Julian number to Gregorian.

Or maybe I'm taking the wrong approach. Can anyone please help to convert a Hijri date according to Umm AlQura calendar to a Gregorian date in golang?

This is what I've so far:

func getJulianNumber(y, m, d int) float64 {
    if m == 1 || m == 2 {
        y -= 1
        m += 12
    }
    a := y / 100
    b := a / 4
    c := 2 - a + b
    e := int(365.25 * (float64(y) + 4716))
    f := int(30.6001 * (float64(m) + 1))
    return float64(float64(c) + float64(d) + float64(e) + float64(f) - 1524.5)
}

func julianToH(jd float64) {
    q := jd + 0.5
    z := int(q)
    w := int((float64(z) - 1867216.25) / 36524.25)
    x := w / 4
    a := int(float64(z) + 1 + float64(w) - float64(x))
    b := a + 1524
    c := int((float64(b) - 122.1) / 365.25)
    d := int(365.25 * float64(c))
    e := int((float64(b) - float64(d)) / 30.6001)
    f := int(30.6001 * float64(e))

    day := int(float64(b) - float64(d) - float64(f) + (q - float64(z)))
    var month, year int
    e1 := e - 1
    if e1 <= 12 {
        month = e1
    } else {
        month = e - 3
    }
    if month == 1 || month == 2 {
        year = int(c - 4715)
    } else {
        year = int(c - 4716)
    }
    fmt.Println(day, month, year)
}

Much obliged!

  • 写回答

3条回答 默认 最新

  • donglv1831 2017-11-30 06:58
    关注

    I created a small helper library hijri to solve my problem. Thanks for all the help!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大