查看当前时区加上UTC时区

查看当前mysql时区

show variables like "%time_zone%"

在这里插入图片描述

若当前时区是UTC,查数据库与时间字段相关的数据时,需要加上时区

import pytz

        start_date = datetime.datetime.strptime(str_time, "%Y-%m-%d %H:%M:%S")
   
       a = start_date.replace(tzinfo=pytz.utc)

result = Book.objects.filter(start_date__gte=a)

猜你喜欢

转载自blog.csdn.net/lxq_9532/article/details/83623609