0

How can I change this naive time to UTC time in python

The time is 2021-08-05T08:32:47.362000Z

st= "2021-08-05T08:32:47.362000Z"

dt = datetime.strptime(st,"%Y-%m-%d %H:%M:%S.%fZ")

I don't know how to parse this time in python. The above given code is what I know I don't know to parse this time.

So this time has been fetched from Django database and what I inserted is a UTC time and I got the above time as a result.

The thing is I need to get utc time.

hamere
  • 125
  • 1
  • 3
  • 8
  • This has already been answered in: https://stackoverflow.com/questions/1595047/convert-to-utc-timestamp – Sefan Aug 05 '21 at 11:48
  • 1
    It also has been answered for [your other question](https://stackoverflow.com/q/68664644/10197418) (except for the 'T' in the date/time string). – FObersteiner Aug 05 '21 at 11:52
  • basically a duplicate of [how-do-i-parse-an-iso-8601-formatted-date](https://stackoverflow.com/questions/127803/how-do-i-parse-an-iso-8601-formatted-date) – FObersteiner Aug 05 '21 at 11:54
  • 1
    Please clarify in how [your earlier question](https://stackoverflow.com/questions/68664644/how-can-i-convert-from-utc-time-to-local-time-in-python) does not cover this one as well. From the looks of it, the only "issue" is replacing a space with a T in the expected format. – MisterMiyagi Aug 05 '21 at 12:02

0 Answers0