I have a date string 18 May 14:30
which corresponds to the British summertime (WEST
or UTC+1
). I would like to convert it to central Euopean (summer)time.
Here is my code
# from datetime import datetime
# from pytz import timezone
d = '18 May 14:30'
# Attempt 1
dd=datetime.strptime(d, '%d %b %H:%M').replace(year=datetime.now().year, tzinfo=timezone('WET'))
dd.astimezone(timezone('CET'))
# datetime.datetime(2019, 5, 18, 16, 30, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>)
# It should be 15:30, not 16:30
# Attempt 2
dd=datetime.strptime(d, '%d %b %H:%M').replace(year=datetime.now().year, tzinfo=timezone('WET'))
# Same result as above
# Attempt 3
dd=datetime.strptime(d, '%d %b %H:%M').replace(year=datetime.now().year, tzinfo=timezone('Etc/GMT-1'))
dd.astimezone(timezone('CET'))
# datetime.datetime(2019, 5, 18, 15, 30, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>)
# This works
So my problem in the third attempt I had to manually specify GMT-1
whereas CET
automatically transforms to CEST
. I hoped this would work identically for WET
(to WEST
).
Besides, what also confuses me is the fact that according to Wiki British summertime should be UTC +1
but I had to set GMT-1
(as GMT+1
returns 18:30
).