将日历日期转换为儒略日期 - python

Convert calendar date to julian date - python

我正在尝试像这样将日历日期转换为:'2018-08-07' 到像这样的儒略历日期 '219'。试了很久,好像运行没思路了。 我正在使用的是儒略日日历: https://landweb.modaps.eosdis.nasa.gov/browse/calendar.html

这是我目前拥有的:

from datetime import date
import datetime
from PyAstronomy import pyasl

df = datetime.datetime(2018, 8, 7, 12)
print(df)
jul = pyasl.jdcnv(df)
print(jul)

您可以为此使用 strftime(有关要使用的指令的说明,请参阅 this):

jul = df.strftime('%j')
>>> jul
'219'
def date_2_julian_string (date):
    return str(date.strftime('%y')) + date.strftime('%j')