Python Question: Year and Day of Year to date?

前端 未结 5 453
面向向阳花
面向向阳花 2020-11-27 17:13

I have a year value and a day of year and would like to convert to a date (day/month/year).

5条回答
  •  被撕碎了的回忆
    2020-11-27 18:11

    2020 Edition:

    import mx.DateTime as dt 
    date = dt.DateTime(yyyy,mm,dd) + dt.DateTimeDeltaFromDays(doy-1)
    

    So, given that you know the year (say, 2020) and the doy (day of the year, say 234), then:

    date = dt.DateTime(2020,1,1) + dt.DateTimeFromDays(233) 
    

    which returns

    2020-08-21 00:00:00.00
    

提交回复
热议问题