Вот текст функции для C++:
double JD (int year, int month, int day, double hour)
{
int BaseDaysInMonths[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
int DaysInMonths;
double Result;
DaysInMonths = BaseDaysInMonths[month-1];
if ((year%4 == 0 && year%100 != 0 || year%400 == 0) && month > 2)
{
DaysInMonths++;
}
if (year <= 0)
{
Result = -0.5 + static_cast<double>((4712 + year)*365 + (4712 + year)/4 + DaysInMonths + (day - 1)) + static_cast<double>(hour)/24.0;
}
else
{
if (static_cast<double>(year)*10000.0 + static_cast<double>(month)*100 + static_cast<double>(day) <= 15821004.0)
{
Result = -0.5 + static_cast<double>((4713 + year - 1)*365 + (4712 + year - 1)/4 + 1 + DaysInMonths + (day - 1)) + static_cast<double>(hour)/24.0;
}
else
{
Result = -0.5 + static_cast<double>((4713 + year - 1)*365 + (4712 + year - 1)/4 + 1 + DaysInMonths + (day - 1)) + static_cast<double>(hour)/24.0 - floor((year - 1 - 1500)/100) + floor((year - 1 - 1200)/400) - 10.0;
}
}
return Result;
}
Предлагаю протестировать любому желающему.
Только рад буду.
P.S. Страшные конструкции вида static_cast<double>("что-то") можно заменять на обычное (double)"что-то."