Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Julian Date to Gregorian 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.

like image 616
fypfyp Avatar asked Jul 22 '13 14:07

fypfyp


People also ask

How do you convert Julian date to Gregorian date in Excel?

In a blank cell, type this formula =TEXT(A1,"yy")&TEXT((A1-DATEVALUE("1/1/"&TEXT(A1,"yy"))+1),"000") and press Enter key, if you need you can apply this formula to a range by dragging the auto fill handle. Tip: A1 is the calendar date you want to convert to Julian date.

What is the Julian date for 2022?

So, for instance, a Julian date of 21-001 represents the first day of the year 2021, or January 1, 2021, while a Julian date of 22-165 represents the 165th day of the year 2022 or June 14, 2022.


1 Answers

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().

like image 100
furq Avatar answered Sep 28 '22 11:09

furq