Converting an unknown timestamp to a datetime in Python
I'm getting a timestamp back from the WordPress API, but the usual method of converting from timestamp to datetime is failing me.
I run this:
print pages[1]['dateCreated']
print datetime.fromtimestamp(pages[1]['dateCreated'])
And get this:
开发者_JS百科20100228T09:25:07
Traceback (most recent call last):
File "C:\Python26\Lib\SITE-P~1\PYTHON~1\pywin\framework\scriptutils.py", line 325, in RunScript
exec codeObject in __main__.__dict__
File "C:\Documents and Settings\mmorisy\Desktop\My Dropbox\python\betterblogmaster3.py", line 28, in <module>
print datetime.fromtimestamp(pages[1]['dateCreated'])
AttributeError: DateTime instance has no attribute '__float__'
Any suggestions?
Assume you've from datetime import datetime
:
print datetime.strptime(pages[1]['dateCreated'],'%Y%m%dT%H:%M:%S')
精彩评论