In [1]:
import datetime

In [2]:
s = '2018-12-31T05:00:30.001000'

In [3]:
dt = datetime.datetime.fromisoformat(s)
print(dt)


2018-12-31 05:00:30.001000

In [4]:
print(dt.tzinfo)


None

In [5]:
s = '2018-12-31T05:00:30.001000+09:00'

In [6]:
dt = datetime.datetime.fromisoformat(s)

In [7]:
print(dt)


2018-12-31 05:00:30.001000+09:00

In [8]:
print(dt.tzinfo)


UTC+09:00

In [9]:
print(dt.isoformat())


2018-12-31T05:00:30.001000+09:00

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'))


2018-12-31T05:00:30.001000+00:00

In [13]:
dt_utc = datetime.datetime.fromisoformat(s.replace('Z', '+00:00'))

In [14]:
print(dt_utc)


2018-12-31 05:00:30.001000+00:00

In [15]:
print(dt_utc.tzinfo)


UTC

In [16]:
print(s.replace('Z', ''))


2018-12-31T05:00:30.001000

In [17]:
dt_none = datetime.datetime.fromisoformat(s.replace('Z', ''))

In [18]:
print(dt_none)


2018-12-31 05:00:30.001000

In [19]:
print(dt_none.tzinfo)


None