When I change the timezone in my django project the dates do change correctly. When the timezone is set to 'UTC' the dates are displayed like this:
This is correct. As you can see these are also the dates which are specified in my database:
But when I change the settings to:
LANGUAGE_CODE = 'nl'
TIME_ZONE = 'Europe/Amsterdam'
USE_I18N = True
USE_L10N = True
USE_TZ = True
The dates inside my application now change to the image below. Only the first two dates are displayed in the correct way, even though nothing has changed except for the timezone.
Does anyone know why this happens, and how I can solve this?
EDIT: Code
def afspraak_maken(request):
form = EventForm(request.POST or None)
if request.POST and form.is_valid():
title = form.cleaned_data['title']
soort = form.cleaned_data['soort']
description = form.cleaned_data['description']
start_time = form.cleaned_data['start_time']
Event.objects.get_or_create(
user=request.user,
title=title,
soort=soort,
description=description,
start_time=start_time,
time_set = time_set
)
Timing.objects.get_or_create(
event_id=find_id,
name= 1,
start_time=localtime(start_time),
end_time=localtime(start_time) + timedelta(hours=1, minutes=30)
)
Timing.objects.get_or_create(
event_id=find_id,
name= 2,
start_time= localtime(start_time) + timedelta(days=7),
end_time= localtime(start_time) + timedelta(days=7,hours=1, minutes=30)
)
Timing.objects.get_or_create(
event_id=find_id,
name= 3,
start_time=localtime(start_time) + timedelta(days=21),
end_time=localtime(start_time) + timedelta(days=21,hours=1, minutes=30)
)
return redirect('afspraak_bewerken', pk=find_id)
return render(request, 'kalender/afspraak_maken.html', {'form': form})
My Timing model:
class Timing(models.Model):
event = models.ForeignKey(Event, null=True, on_delete=models.CASCADE)
name = models.CharField(max_length=200)
start_time = models.DateTimeField()
end_time = models.DateTimeField()
comment = models.CharField(max_length=300,null=True, blank=True)
One of the tables where I display my dates
<table class="homepage-table mt-2 mb-2" id="myTable2">
<tr>
<th> Afspraak</th>
<th> Training</th>
<th> Start tijd</th>
<th> Eind tijd</th>
<th> Locatie</th>
<th> Trainer</th>
</tr>
{% for timing in timing%}
<tr>
<td> {{timing.name}}</td>
<td> {{timing.event.title}}</td>
<td> {{timing.start_time|date:'d-m-Y H:i'}}</td>
<td> {{timing.end_time|date:'d-m-Y H:i'}}</td>
<td> {{timing.event.locatie}}</td>
<td> {{timing.event.trainer}}</td>
</tr>
{% endfor%}
</table>


