1

I have something like

from dateutil import parser
my_datetime = parser.parse("2020-06-19 12:10:10.12345+02")

I want to print this as 2020-06-19 10:10:10.12345Z

Lieuwe
  • 1,734
  • 2
  • 27
  • 41
  • 3
    Does this answer your question? [Convert UTC datetime string to local datetime](https://stackoverflow.com/questions/4770297/convert-utc-datetime-string-to-local-datetime) – Chase Jun 19 '20 at 16:23

1 Answers1

1

You can use dateutil.tz to access timezones and then express a given date with that timezone with .astimezone().

from dateutil.parser import parse
from dateutil.tz import tzutc

my_datetime = parse("2020-06-19 12:10:10.12345+02")

print(my_datetime.astimezone(tzutc()))
AJ_
  • 1,455
  • 8
  • 10