Reputation: 81
I am attempting to convert a floating point number, in this case seconds, into a YYMMDDHHMM format. I have tried numerous ways only to either get an error dealing with the fact that I haven't properly converted the float OR that when I have completed the conversion it is not in UTC/GMT time. This occured when I tried to use the function "ctime". When I inputted 0 for s when using ctime it printed a time 6 hours before Jan 1st, 1970.
Here's what I have that's missing the conversion:
import time
s = 1226368439.04
#conversion of some sort here
print time.strftime(s)
Any assistance would be wonderful.
Upvotes: 0
Views: 1754
Reputation: 93
Try this one
import time
t = 1226368439.04
time.strftime('%Y%m%d%H%M%S', time.localtime(t))
20081111072359
time.strftime('%Y%m%d%H%M%S', time.gmtime(t))
'20081111015359'
Upvotes: 1