儒略日反推计算日期
把儒略日反推计算日期写成了一个小程序,大家可以调用,在参数中指定就可以返回需要的结果了。
Good Luck!
int mjd2date ( long mjd, int *pYear, int *pMonth, int *pDay )
{
#define AD 678576
int icen4;
int icen;
int iyr4;
int iyr;
int imon;
int iday;
if (mjd > 2973483)
return (ERROR);
if ((mjd += AD - 1) < 0)
return (ERROR);
icen4 = mjd / 146097;
mjd -= (icen4 * 146097);
if ((icen = mjd / 36524) == 4)
icen = 3;
mjd -= (icen * 36524);
iyr4 = mjd / 1461;
mjd -= (iyr4 * 1461);
if ((iyr = mjd / 365) == 4)
iyr = 3;
iday = mjd - iyr * 365;
for (imon = 0; iday >= 0; imon++)
iday = iday - monlen[imon] - ((iyr == 3 && imon == 1) ? 1 : 0);
imon--;
iday = iday + monlen[imon] + ((iyr == 3 && imon == 1) ? 1 : 0);
*pYear = icen4 * 400 + icen * 100 + iyr4 * 4 + iyr + 1;
*pMonth = imon + 1;
*pDay = iday + 1;
return (OK);
}