Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- now_time = datetime.datetime.now() # 如果数据库保存的是UTC时间,程序不会蹦但是会提示你这不是本地时间
- now_time_utc = datetime.datetime.utcnow()
- 查询本周产生的数据
- # 当前天 显示当前日期是本周第几天
- day_num = cur_time.isoweekday()
- # 计算当前日期所在周一
- monday = (cur_time - datetime.timedelta(days=day_num))
- # 查询一周内的数据
- all_datas = YourModel.objects.filter(time__range=(now_time, monday))
- 查询本月的数据
- all_datas = YourModel.objects.filter(time__month=now_time.month)
- 查询本年的数据
- all_datas = YourModel.objects.filter(time__year=now_time.year)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement