I have the following string:
'2017-08-15T13:34:35Z'
How to convert this string to object that I can call .isoformat()
?
someobject = convert('2017-08-15T13:34:35Z')
someobject.isoformat()
How to implement convert()
?
I have the following string:
'2017-08-15T13:34:35Z'
How to convert this string to object that I can call .isoformat()
?
someobject = convert('2017-08-15T13:34:35Z')
someobject.isoformat()
How to implement convert()
?
Here to parse a string to date time, then you can:
def convert(s):
return datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ')
someobject = convert('2017-08-15T13:34:35Z')
print(someobject.isoformat())
You can use dateutil's parser:
>>> import dateutil.parser
>>> date = dateutil.parser.parse('2017-08-15T13:34:35Z', ignoretz=True)
>>> date
datetime.datetime(2017, 8, 15, 13, 34, 35)
>>> date.isoformat()
'2017-08-15T13:34:35'