In [1]:
import datetime
In [2]:
s = '2018-12-31T05:00:30.001000'
In [3]:
dt = datetime.datetime.fromisoformat(s)
print(dt)
In [4]:
print(dt.tzinfo)
In [5]:
s = '2018-12-31T05:00:30.001000+09:00'
In [6]:
dt = datetime.datetime.fromisoformat(s)
In [7]:
print(dt)
In [8]:
print(dt.tzinfo)
In [9]:
print(dt.isoformat())
In [10]:
s = '2018-12-31T05:00:30.001000Z'
In [11]:
# dt = datetime.datetime.fromisoformat(s)
# ValueError: Invalid isoformat string: '2018-12-31T05:00:30.001000Z'
In [12]:
print(s.replace('Z', '+00:00'))
In [13]:
dt_utc = datetime.datetime.fromisoformat(s.replace('Z', '+00:00'))
In [14]:
print(dt_utc)
In [15]:
print(dt_utc.tzinfo)
In [16]:
print(s.replace('Z', ''))
In [17]:
dt_none = datetime.datetime.fromisoformat(s.replace('Z', ''))
In [18]:
print(dt_none)
In [19]:
print(dt_none.tzinfo)