这似乎很容易,但它给我带来了困惑。我的代码是
today = datetime.datetime.now()
StatusObj = Status.objects.filter(taskPeople__people__email = useremail,dateCreated__year = today.year, dateCreated__month = today.month, dateCreated__day = today.day)
预计它将过滤日期为今天的查询。但它不会过滤而是过滤一天后的查询。 当我这样做的时候。
today.day
>> 20
Status.objects.filter(taskPeople__people__email = useremail,dateCreated__year = today.year, dateCreated__month = today.month, dateCreated__day = today.day)[0].dateCreated.day
>>19
答案 0 :(得分:1)
您应该使用django.utils.timezone.now
代替datetime.datetime.now
。
from django.utils import timezone
today = timezone.now()
...
阅读时区文档的troubleshooting部分中的问题#3。