Je reçois un horodatage de l'API WordPress, mais la méthode habituelle de converting from timestamp to datetime ne fonctionne pas.Conversion d'un horodatage inconnu en datetime en Python
Je cours ceci:
print pages[1]['dateCreated']
print datetime.fromtimestamp(pages[1]['dateCreated'])
Et obtenez ceci:
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__'
Toutes les suggestions?
[ 'timestamp' censé être un flotteur] (http://docs.python.org/library/datetime.html#datetime.date.fromtimestamp). Vous avez une chaîne, analysez votre chaîne avec ['datetime.strptime'] (http://docs.python.org/library/datetime.html#datetime.datetime.strptime) et vous obtiendrez l'objet' datetime'. – SilentGhost
'exec codeObject dans __main __.__ dict__' Qu'est-ce que cela fait? Si vous voulez garder votre code secret, nous ne pouvons rien faire, n'est-ce pas? En outre, si vous utilisez réellement ceci, vous manquez le point d'utiliser Python. –
Ce que vous avez là est un horodatage ISO 8601, pas un horodatage Unix. Voir http://stackoverflow.com/questions/969285/how-do-i-translate-a-iso-8601-datetime-string-into-a-python-datetime-object –