草庐IT

AmbiguousTimeError

全部标签

python - 从 Django 的 make_aware 解决 AmbiguousTimeError

我有一个代码如下:fromdjango.utils.timezoneimportget_current_timezone,make_awaremake_aware(some_datetime,get_current_timezone())make_aware调用偶尔会引发AmbiguousTimeError:2013-11-0301:23:17我从Django文档中知道这是一个夏令时问题,而且这个时间戳实际上是不明确的。现在我该如何解决它(比如这可能是两个可能时间中的第一个)? 最佳答案 预防药您应该首先使用以下方法避免天真的日期时

Python pytz : non-existent time gets AmbiguousTimeError, 不是 NonExistentTimeError

如何判断本地时间是否不存在?我正在尝试使用pytz,但它会引发AmbiguousTimeError,而不是NonExistentTimeError。由于夏令时,2013-3-3102:30在哥本哈根永远不会发生。local_tz=timezone('Europe/Copenhagen')try:non_e=local_tz.localize(datetime.datetime(2013,3,31,2,30),is_dst=None)exceptpytz.AmbiguousTimeError:print"AmbiguousTimeError"它转到异常处理程序。我试过:exceptpyt