2

I have an epoch time that is in Seconds.PartOfSecond format e.g. 1581218900.17436. How can this be used within time.strftime() ?

import time
curTime = time.time()
# Following is not correct but gives idea what i'm looking for
formattedTime = time.strftime('%A %B %e, %Y %t', curTime) 

Update The answer this has been closed for is not imo an obvious replacement: how would one know we need to convert to datetime.datetime? The answer below is more to the point.

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560

1 Answers1

4

You need pass your second to gmtime

import time
s=time.gmtime(1581218900.17436)
time.strftime("%Y-%m-%d %H:%M:%S", s)
'2020-02-09 03:28:20'
time.strftime('%A %B %e, %Y %t', s)
'Sunday February  9, 2020 \t'
BENY
  • 317,841
  • 20
  • 164
  • 234