0

I have datetime value in format of 2022-01-26T07:01:36-08:00 (based on which user fetches data, it will have local timezone, like -08:00, +05:30)

I want to convert this time into UTC Time.

I saw multiple example of pytz but couldn't figure out how to convert using pytz or datetime. datetime value will be based on machine timezone so I can't hard code timezone value also.

mihir6692
  • 177
  • 1
  • 4
  • 19
  • This question has already been answered [here](https://stackoverflow.com/questions/79797/how-to-convert-local-time-string-to-utc) if the solution doesn't work, please provide the code you tried – Emmanuel-Lin May 27 '22 at 08:24
  • 1
    TL;DR: parse the string into a `datetime` object, then just do `.astimezone(timezone.utc)`. – deceze May 27 '22 at 08:32

0 Answers0