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)