从儒略日起计算公历年,月,日的默认值是多少(例如1721119)? [英] What are the default values taken (say 1721119) to calculate the Gregorian Year, Month, Day from Julian Day

查看:245
本文介绍了从儒略日起计算公历年,月,日的默认值是多少(例如1721119)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常感谢!

以下代码段是一个给定儒略日的年份,月份和日期的函数.

The following code snippet is a function that gives me Year, Month and Day for a given Julian Day..

能否请您告诉我这里的常数表示什么.我可以在网上找到此代码,但是没有人解释此处采用的默认值.另外,如果有人可以解释该功能的作用.

Can you please tell me what does the constants here signify. I can find this code all over the net but nobody explains about the default values taken here. Also if anyone can explain what the function will do.

假设我为JD传递的值为2456447.

Suppose, the value i am passing for JD is 2456447..

VOID GetGregorianDate(LONG JD, PWORD Year, PWORD Month, PWORD Day)
{
    LONG j, y, d, m;
    j = JD - 1721119;            //what is this value - 1721119 (may be related to day.. but how ?)
    y = (4 * j - 1) / 146097;    //what is this value - 146097 (may be related to year.. but how ?)
    j = 4 * j - 1 - 146097 * y;
    d = j / 4;
    j = (4 * d + 3) / 1461;        // ?
    d = 4 * d + 3 - 1461 * j;
    d = (d + 4) / 4;
    m = (5 * d - 3) / 153;        // ?
    d = 5 * d - 3 - 153 * m;
    d = (d + 5) / 5;
    y = 100 * y + j;
    if (m < 10)
    {
        m = m + 3;
    }
    else 
    {
        m = m - 9;
        y = y + 1;
    }

    *Year   = (WORD) y;
    *Month  = (WORD) m;
    *Day    = (WORD) d;
}

推荐答案

它们只是公历和选择为儒略时期开始的任意日期的人工产物.

They're just artifacts of the Gregorian calendar and the arbitrary date chosen as the start of the Julian epoch.

  • 1721119是从JD 0到1BC年3月开始的偏移量(因为没有0AD);减去后得出自那时以来的天数.选择三月作为一年的开始",以便leap日到结束",这使计算更简单.
  • 146097是四个世纪以来的天数,这是leap年周期重复所需的时间.
  • 1461是四年中的天数(较短的leap年周期).
  • 153是连续5个月的天数,介于31天和30天之间(3月至7月或8月至12月).
  • 3和9的各种加减法是为了将一年的开始"恢复到一月.

巧妙的算术将它们组合在一起,以考虑leap年和不同的月份长度来给出正确的天数.

The fiddly arithmetic puts them all together to give the correct count of days, taking into account leap years and varying month lengths.

本文(引自 Wikipedia )描述了逆计算中的各种魔术数字(格里高利历法到朱利安日)出现;算法中的数字以相似的方式出现.

This paper (referenced from Wikipedia) describes how the various magic numbers in the inverse calculation (Gregorian date to Julian day) arise; the numbers in your algorithm arise in a similar way.

这篇关于从儒略日起计算公历年,月,日的默认值是多少(例如1721119)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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