How to convert Python datetime dates to decimal/float years

前端 未结 7 1396
感动是毒
感动是毒 2020-12-09 18:18

I am looking for a way to convert datetime objects to decimal(/float) year, including fractional part. Example:

>>> obj = SomeObjet()
>>> o         


        
7条回答
  •  余生分开走
    2020-12-09 19:01

    If you want to include the minutes and seconds use this:

    YearF=[(x.timetuple().tm_yday-1+x.timetuple().tm_hour/24+x.timetuple().tm_min/(60*24)+x.timetuple().tm_sec/(24*3600))/(365+((x.timetuple().tm_year//4)==(x.timetuple().tm_year/4)))+x.timetuple().tm_year for x in DateArray]
    

提交回复
热议问题