1. 程式人生 > >TypeError: can't compare offset-naive and offset-aware datetimes bugfix

TypeError: can't compare offset-naive and offset-aware datetimes bugfix

bject 正常 offset sdn log blank aware lan 存儲

參考:https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/#naive-and-aware-datetime-objects

起因:正常的dateime.now()得到的日期不能和Django數據庫裏面存儲的日期數據做對比,兩個解決辦法:

1、是把Django配置裏面的USE_TZ設置成False,這樣Django的數據就沒有時區信息了。

2、是在這個對比情景下,不要用datetime.now()來得當前數據,用以下代碼:

from django.utils import timezone  
  
now = timezone.now()

TypeError: can't compare offset-naive and offset-aware datetimes bugfix