Python convert timestamp with offset into actual local time for MySQL INSERT

How do I convert a timestamp in Python, such as 2020-05-28 02:00:00+02:00 into 2020-05-28 04:00:00, where the offset +02:00 was added to show the right local time at 04:00?

I have tried the following code for conversion:

>>> datetime.strptime('2020-05-28 02:00:00+02:00', '%Y-%m-%d %H:%M:%S%z').strftime('%Y-%m-%d %H:%M:%S') 

Giving,

‘2020-05-28 02:00:00’

Instead of,

‘2020-05-28 04:00:00′

But how could I display the latter result showing the actual local day and time? The converted timestamp will then be added into a MySQL database.

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.