-3

How to convert JD to date, please? Here is the solution in the opposite direction.

For instance, 2416834.8134 is 20.12.1904

Elena Greg
  • 1,061
  • 1
  • 11
  • 26

1 Answers1

2

You can convert julian date to python datetime as follows:

import math
from datetime import datetime
BASE_JD = 1721424.5  # Julian date of 1 January, 1
user_JD = 2416834.8134
date = datetime.fromordinal(math.floor(user_JD - BASE_JD))
# Output: datetime.datetime(1904, 12, 20, 0, 0)

Julian date of 1 Jan, 1 is taken from Julian date variants - wikipedia.

To print this date in any desired format, datetime.strftime method can be used

date.strftime('%d.%m.%Y')
# Output: '20.12.1904'

Documentation-

datetime.fromordinal: "Return the datetime corresponding to the proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1"

Mohit Khandelwal
  • 541
  • 6
  • 14