How to convert python string to utc time?

question: how to convert string to utc format time?

how to convert the string "20181221" to the
target format: "2018-12-21T00:00:00.000Z"

tried

from dateutil.parser import parse
import dateutil
a = parse("20181222").isoformat()
print(a)

unable to get the format with 000.Z

before using the parse function directly, the code is as follows:

from dateutil.parser import parse
import dateutil
a = parse("20181222")

is then saved in mongodb, which is automatically saved to include 000.Z format

the author finally hopes to transmit the data of DataFrame in pandas to mongodb, but because the previous data date format is "2018-12-21T00:00:00.000Z",
can only get "2018-12-22T00 mongodb" now.
ask how to convert the string "20181221" into "2018-12-21T00:00:00.000Z".
is grateful!

other methods have been tried, but still can"t get the format you want.

import arrow
arrow.get("20181221").datetime

and

import dateutil
u = dateutil.tz.tzutc()
u2 = dateutil.tz.gettz("America/Chicago")
date1 = datetime.datetime(2010,5,2,11,10,tzinfo=u)
date2 = datetime.datetime(2010,5,2,11,10,tzinfo=u2)


datetime:

>>> source='2018-08-01'
>>> import datetime as dt
>>> my_dt=dt.datetime.fromisoformat(source)
>>> my_dt.isoformat(timespec='milliseconds')+'Z'
'2018-08-01T00:00:00.000Z'
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be97da-545df.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be97da-545df.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?