delorian

when does `datetime.now(pytz_timezone)` fail?

我们两清 提交于 2019-11-27 08:43:01
delorean docs show this way to get the current time in a given timezone using datetime : from datetime import datetime from pytz import timezone EST = "US/Eastern" UTC = "UTC" d = datetime.utcnow() utc = timezone(UTC) est = timezone(EST) d = utc.localize(d) d = est.normalize(EST) and compare it with the delorian-based code: from delorean import Delorean EST = "US/Eastern" d = Delorean(timezone=EST) I believe the datetime example should be written as: from datetime import datetime import pytz eastern_timezone = pytz.timezone("US/Eastern") d = datetime.now(eastern_timezone) that is more concise.

when does `datetime.now(pytz_timezone)` fail?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 14:16:35
问题 delorean docs show this way to get the current time in a given timezone using datetime: from datetime import datetime from pytz import timezone EST = "US/Eastern" UTC = "UTC" d = datetime.utcnow() utc = timezone(UTC) est = timezone(EST) d = utc.localize(d) d = est.normalize(EST) and compare it with the delorian-based code: from delorean import Delorean EST = "US/Eastern" d = Delorean(timezone=EST) I believe the datetime example should be written as: from datetime import datetime import pytz