5

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.

4

1 回答 1

7

这个答案显示了从 Unix 时间戳转换为儒略日期的方法。这就是你在 Lua 中的做法:

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

所以这就是你在另一个方向上转换的方式:

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

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

于 2013-07-22T16:09:17.943 回答