我有這樣的代碼,而且我發現它並沒有過濾我想要的日期,django沒有過濾日期時間?
這裏是我的代碼:
today = 2014-12-24 00:00:00+08:00 #<type 'datetime.datetime'>
tomorrow = 2014-12-25 00:00:00+08:00 #<type 'datetime.datetime'>
for i in Showtime.objects.filter(movie_id=movieid,theater_id=theaterid,datetime__range=(today,tomorrow)):
print i
if i.mvtype not in movietimes:
movietimes[i.mvtype] = []
movietimes[i.mvtype].append(i.movietime.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
return movietimes
我打印i
,看看有什麼happened.and我發現它沒「T篩選日期正確
2014-12-23 16:10:00+00:00
2014-12-24 09:00:00+00:00
2014-12-25 05:00:00+00:00
2014-12-23 06:50:00+00:00
2014-12-23 11:10:00+00:00
2014-12-23 13:20:00+00:00
2014-12-23 15:30:00+00:00
,只顯示12-24和12-25之間的日期:
2014-12-23 16:10:00+00:00 (this +8 hr is 2014-12-24)
2014-12-24 09:00:00+00:00
請幫助我謝謝!
您是否閱讀過「range」的文檔? https://docs.djangoproject.com/zh/dev/ref/models/querysets/#range –