How do you convert a python time.struct_time object into a ISO string?
Using time.strftime()
is perhaps easiest:
iso = time.strftime('%Y-%m-%dT%H:%M:%SZ', timetup)
Demo:
>>> import time
>>> timetup = time.gmtime()
>>> time.strftime('%Y-%m-%dT%H:%M:%SZ', timetup)
'2013-10-11T13:31:03Z'
You can also use a datetime.datetime()
object, which has a datetime.isoformat()
method:
>>> from datetime import datetime
>>> datetime(*timetup[:6]).isoformat()
'2013-10-11T13:31:03'
This misses the timezone Z
marker; you could just add that.