Python datetime difference between .localize and tzinfo
问题 Why do these two lines produce different results? >>> import pytz >>> from datetime ipmort datetime >>> local_tz = pytz.timezone("America/Los_Angeles") >>> d1 = local_tz.localize(datetime(2015, 8, 1, 0, 0, 0, 0)) # line 1 >>> d2 = datetime(2015, 8, 1, 0, 0, 0, 0, local_tz) # line 2 >>> d1 == d2 False What's the reason for the difference, and which should I use to localize a datetime? 回答1: When you create d2=datetime(2015, 8, 1, 0, 0, 0, 0, local_tz) in this way. It does not handle daylight