Reputation: 1109
I have a time stamp in the format 20140110143000
I need to convert it into a human readble format.
I am using the following code:
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(20140110143000))
But it is giving the following error:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(20140110143000))
ValueError: (22, 'Invalid argument')
Can any body please help me out?
Upvotes: 0
Views: 1817
Reputation: 6729
coincidentally datetime
objects prints timestamp in %Y-%m-%d %H:%M:%S
format. So, for printing 20140110143000
in required format you can simply convert it to a datetime object and print it
from datetime import datetime
print datetime.strptime("20140110143000", "%Y%m%d%H%M%S")
output
2014-01-10 14:30:00
Upvotes: 1