将朱利安日期转换为格里高利日 [英] Convert Julian Date to Gregorian Date

查看:612
本文介绍了将朱利安日期转换为格里高利日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Lua写一个计算日落/日出的应用程序,为此,我必须将公历日期转换为朱利安日期,然后从那里进行所有复杂的数学等。



我已经完成了硬数学,但现在我需要将儒略日期(2456495.6833865作为例子)转换成公历,随着时间的推移。我发现唯一可以做到这一点的代码只有日期,年份和月份,但没有提到时间(我认为这是一小部分时间,在这种情况下是小数点后的数字) / p>

任何帮助将不胜感激 - 下面的网站有功能,但我找不到任何代码或方法:



http://ssd.jpl.nasa.gov/tc.cgi#top



再次感谢



FYP。

解决方案

此答案显示了将Unix时间戳转换为朱利安日期这是你如何在Lua中做的:

  local julian =(os.time()/ 86400)+ 2440587.5 
print(julian)
- 2456496.1647338

所以这是你' d转换为另一个方向:

  print((julian  -  2440587.5)* 86400))
- 1374508633

然后,您可以使用 os.date()将其转换为日期和时间,


I'm writing an application in Lua that calculates the sunset/sunrise, and to do this I had to convert the Gregorian date in to Julian days initially and do all the complex maths and such from there.

I've completed the hard maths, but now I need to convert the Julian date (2456495.6833865 as an example) back to a Gregorian one, complete with the time. The only code I've found that can do this only has the day, year and month, but no mention of the time (which I believe is expressed as a fraction of the day, in this case the numbers after the decimal point)

Any help would be greatly appreciated - The website below has the functionality but I cant find any code or ways of doing it:

http://ssd.jpl.nasa.gov/tc.cgi#top

Thanks again,

FYP.

解决方案

This answer shows the way to convert from a Unix timestamp to a Julian date. This is how you'd do it in Lua:

local julian = (os.time() / 86400) + 2440587.5
print(julian)
-- 2456496.1647338

And so this is how you'd convert in the other direction:

print( (julian - 2440587.5) * 86400) )
-- 1374508633

You can then convert this into a date and time using os.date().

这篇关于将朱利安日期转换为格里高利日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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