Django Display the correct time - depending on the time zone

What is the best way to display the time according to the user's time zone?

I have a Post object:

class Post(models.Model):
   submit_date = models.DateTimeField(auto_now_add=True)
   ...

In the template, I have something like this:

{% load tz %}
<p> TIME: {{ post_object.submit_date|localtime }} </p>

In settings.py:

USE_TZ = True
USE_L10N = True
TIME_ZONE = 'UTC'

Perhaps I am missing something obvious, all I want is a template for displaying user time depending on its time zone. Should I do some logic in the views.py file?

+4
source share
1 answer

It depends on the version of django and the time zone of the user. If you have a custom time zone saved in your user profile or somewhere else, you can use timezonethe template tag:

{% timezone "Europe/Paris" %}
    Paris time: {{ value }}
{% endtimezone %}

timezone :

{{ value|timezone:"Europe/Paris" }}

, ( , ). , , fasouto ( , ).

PS: , / .

+2

All Articles