Convert calendar date to julian date - python

一曲冷凌霜 提交于 2021-01-28 11:48:07

问题


I am trying to convert calendar date like so: '2018-08-07' to julian calendar day like so '219'. I have tried for a long time and seem to run out of ideas. The julian day calendar is this one I am using: https://landweb.modaps.eosdis.nasa.gov/browse/calendar.html

Still new to programming so I am trying to figure out where I went wrong. Appreciate your help, folks.

This is what I have so far:

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)

回答1:


You can use strftime for this (see this for a description of directives to use):

jul = df.strftime('%j')
>>> jul
'219'


来源:https://stackoverflow.com/questions/53107367/convert-calendar-date-to-julian-date-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!