Extract day of year and Julian day from a string date

前端 未结 9 2027
臣服心动
臣服心动 2020-11-27 06:51

I have a string \"2012.11.07\" in python. I need to convert it to date object and then get an integer value of day of year and also Julian day

9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 07:03

    def JulianDate_to_date(y, jd):
        month = 1
        while jd - calendar.monthrange(y,month)[1] > 0 and month <= 12:
            jd = jd - calendar.monthrange(y,month)[1]
            month += 1
        date = datetime.date(y,month,jd).strftime("%m/%d/%Y")
        return date
    

提交回复
热议问题