R
R
r1dddy4sv2021-02-28 19:35:33
Python
r1dddy4sv, 2021-02-28 19:35:33

How to convert one timezone to another?

I have dates of the form: 2.3
at 1:00 PM CET 10.1
at 0:00 AM CEST
3.3 at 7:59 PM (UTC+9) date format by specifying the time zone. How to do this, I do not know. Thanks in advance


Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sotanodroid, 2021-02-28
@sotanodroid

You need to escape the `datetime.strptime` method.
Signatures here:
https://docs.python.org/3/library/datetime.html#st...
Something like this for "1:00 PM UTC" :

date_object = datetime.strptime(date_string, "%I:%M %p %Z")

But for timezones like CET, CEST, you need an additional lib https://pypi.org/project/pytz/
First you parse the time without a timezone, then you bring it to the desired one using pytz

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question