# How does one convert between Modified Julian Date (MJD) and a standard (mm/dd/yr, hr:mm:ss)

I looked online and couldn't see an actual formula or anything, so I figured I'd ask here.

If I had an MJD like the following: 59145.6678

How would I convert that to a month, day, and year with the hour and minutes?

• en.wikipedia.org/wiki/Julian_day says MJD 0 is 0:00 November 17, 1858 (UTC). Since you know Python, you can use the standard datetime module to write conversion code. Nov 20, 2022 at 18:54

A modified Julian Date is just a Julian Date minus 2,400,000.5. So you could just add 2,400,000.5 to the MJD, and use existing Julian Date routines to do the conversion. Here are some routines which break a JD into Month, Day, Year and vice versa.

But, if you're using any modern language which has built in date routines, I highly recommend you use those instead to avoid the many special cases when dealing with dates.

Most languages will accept the time in seconds since Jan 1, 1970 ("Unix Time") as an input to date routines, and the functions below will convert a MJD to/from Unix Time in milliseconds:

function ModifiedJulianDateFromUnixTime(t){
return (t / 86400000) + 40587;
}

function UnixTimeFromModifiedJulianDate(jd){
return (jd-40587)*86400000;
}


The above functions are in Javascript, but it is trivial to convert to nearly any other language. Some languages accept seconds rather than milliseconds, so divide by 1000 for those.

For, example, in JavaScript, the code below will get all of the components.

date = new Date(UnixTimeFromModifiedJulianDate(59145.6678));
day=date.getDate();
year=date.getYear()+1900;
month=date.getMonth()+1;
hour=date.getHours();
minutes=date.getMinutes();
seconds=date.getSeconds();
milli=date.getMilliseconds();
console.log(year,month,day,hour,minutes,seconds,milli);


Returns:

2020 10 23 12 1 37 920


You must be careful about any dates prior to Oct 15, 1582 (the start of the Gregorian Calendar). What answer is correct depends a lot on what your intentions are. The routines in the link above assume anything before the Gregorian Calendar are in the Julian Calendar, which matches what JPL Horizons does.

• I should note the "getHours()" etc, functions will return values based on the local time zone, while the input is assumed to be UTC. Use the "getUTCHours()", etc, functions to get the result in UTC. Nov 21, 2022 at 4:32