我是Python新手。我的datetime参数为2020-03-20T04:00:00.000Z
。如何将其转换为日期时间,以及如何将日期和时间分开。
我的代码小人如下:
schedule_time = models.DateTimeField() #This is my model code
我对查询集的查看代码为:
def get_queryset(self):
queryset = AppointmentSerial.objects.all()
status = self.request.query_params.get('status')
schedule_time = self.request.query_params.get('schedule_time')
if not status:
queryset = queryset.exclude(status="DELETE")
if schedule_time:
dateTime = datetime.datetime.strptime(schedule_time, "%Y-%m-%d %H:%M:%S")
date = datetime.datetime.strptime(dateTime, "%Y-%m-%d %H:%M:%S").strftime("%Y,%m,%d")
time = datetime.datetime.strptime(dateTime, "%Y-%m-%d %H:%M:%S").strftime("%H:%M:%S")
if time == '00:00:00':
queryset = queryset.filter(schedule_time_date=datetime.date(date))
else:
queryset = queryset.filter(schedule_time=schedule_time)
return queryset
当时间为0时,如何按datetime字段的日期值查询?