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())
import pytz import datetime print(datetime.datetime.strptime('2020-02-03T14:33:22Z', '%Y-%m-%dT%H:%M:%SZ').replace(tzinfo=pytz.UTC))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'
import pytz import datetime print(datetime.datetime.strptime('2020-02-03T14:33:22Z', '%Y-%m-%dT%H:%M:%SZ').replace(tzinfo=pytz.UTC))