Reputation: 39
The above image shows 24 hours timing using angular.
The above image shows timing in 12 hours in the admin panel.
This is the model I want to fetch records sent to Angular
class Appointment(models.Model):
service_requested = models.TextField()
customer = models.ForeignKey(Customer, on_delete = models.CASCADE)
appointment_date_time = models.DateTimeField()
I tried this but I got a 24-hour time. Is there any way to convert time to 12-hours. and then send it
queryset = Appointment.objects.all()
Is it the correct way to convert time to 12-hour?
from datetime import datetime
queryset = Appointment.objects.all().annotate(
date_time = datetime.strptime('appointment_date_time','%Y-%m-%d %I:%M %p')
).values('service_requested','customer','date_time')
Upvotes: 0
Views: 324
Reputation: 39
It is simple, see this:
<td>{{book.appointment_date_time| date:'medium'}}</td>
In html file i just add template filter.
For more detail about the date format see this https://docs.angularjs.org/api/ng/filter/date
Upvotes: 1