How can I convert a decimal representation of a day in the year to a timestamp with all the parts, both the full date and the time?
For example, my first decimal is 22.968530853511766
and I want it in a nice timestamp format.
How can I convert a decimal representation of a day in the year to a timestamp with all the parts, both the full date and the time?
For example, my first decimal is 22.968530853511766
and I want it in a nice timestamp format.
Use a
timedelta()
object with your value as thedays
parameter; add it to midnight December 31st of the previous year:Demo:
A
datetime
object can be formatted any number of ways with thedatetime.strftime()
method; I relied on the defaultstr()
conversion as called byprint()
in the demo.