0

I have a very silly question... how I can convert this timestring to a normal datetime?

20170509.54166667

Greetings.

S.Kociok
  • 168
  • 1
  • 14
  • Not really... I have a workaround... but i think there is a shorter way... maybe I'm only confused. :D the number after the point *24 rounded is exacactly the time... – S.Kociok May 14 '21 at 14:14
  • Maybe you can turn it into a string and then divide the parts into individual segments? Eg: 20170509.54166667 -> 2017 05 09 5 41 66667. – theknightD2 May 14 '21 at 14:15
  • I’m still confused what 54166667 is... – theknightD2 May 14 '21 at 14:17
  • The front is correct... the Time is: 2017-05-09 13:00... – S.Kociok May 14 '21 at 14:17
  • 1
    You can do `datetime.strptime("20170509", "%Y%m%d")` to parse the date. I'm not sure how the part after the dot is supposed to be interpreted. – Samwise May 14 '21 at 14:24
  • @Samwise I think the dupe linked is inappropriate; the OP obviously has no Unix timestamp (it's yyyymmdd.dayfraction instead). Parse the integer part with strptime and add the fractional part as timedelta. – FObersteiner May 14 '21 at 16:06

1 Answers1

0

You can do:

import datetime

datetime.datetime.fromtimestamp(20170509.54166667)

# which returns this:
datetime.datetime(1970, 8, 22, 11, 55, 9, 541667)
EM789
  • 56
  • 4