Celestial Programming : Julian Date Algorithms

These two functions below are short versions that work with the time elapsed in milliseconds since Jan 1, 1970 UTC. Most languages have routines to produce time in this way, so it may be preferable to the long routine below. Since almost all libraries have issues dealing with dates before Oct 15, 1582, be very careful trying to modify these routines to work with dates before then. If you have the time in seconds, rather than milliseconds, change 86400000 to 86400.
 
function JulianDateFromUnixTime(t){
	//Not valid for dates before Oct 15, 1582
	return (t / 86400000) + 2440587.5;
}

function UnixTimeFromJulianDate(jd){
	//Not valid for dates before Oct 15, 1582
	return (jd-2440587.5)*86400000;
}	
	
JavaScript functions to convert to and from a Julian Date. Algorithms from Astonomical Algorithms (Meeus).

Convert Gregorian Date to Julian Date:

- -    : :
Julian Date:

Convert Julian Date to Gregorian Date:

Julian Date:
- -    : :