My code of pytz astimezone as below adds extra 56 minutes when converting New York time to London time, when it is not for year 1900.
The other similar questions seem to be converting to or from a time zone to the default machine time zone. What I fail here is converting from a specific time zone to another specific time zone
Can someone help to point out what went wrong? Thanks a lot
import datetime
import pytz
import sys
print(sys.version)
NYTime = datetime.datetime(2023,3,28,6,0,0,tzinfo=pytz.timezone('America/New_York'))
print("NYTime is " + NYTime.strftime("%Y%m%d-%H:%M:%S"))
LondonTime = NYTime.astimezone(pytz.timezone('Europe/London'))
print("LondonTime is " + LondonTime.strftime("%Y%m%d-%H:%M:%S"))
returns
3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]
NYTime is 20230328-06:00:00
LondonTime is 20230328-11:56:00
and the below
import datetime
import pytz
import sys
print(sys.version)
NYTime = datetime.datetime(2023,3,28,6,0,0,tzinfo=pytz.timezone('America/New_York'))
print("NYTime is " + NYTime.strftime("%Y%m%d-%H:%M:%S"))
LondonTime = pytz.timezone('Europe/London').localize(NYTime)
print("LondonTime is " + LondonTime.strftime("%Y%m%d-%H:%M:%S"))
returns
ValueError: Not naive datetime (tzinfo is already set)