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条)

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?