How to display all datetime objects in a different timezone in Django

Viewed 196

I am relatively new to Django.

All of my datetime objects are in UTC and my settings.py file has TIME_ZONE = 'UTC'

When these datetime objects show up in my html template using {{ obj.datetime }}, they are dislayed in UTC, I want to display them in UTC-05:00.

How can I change this?

Note: I am using class-based views

1 Answers

You can change timezone global in your settings.py set:

TIME_ZONE = 'America/Panama'

for UTC-05:00

Or you can use filter timezone in template - see Django documentation

{% load tz %}

{{ obj.datetime|timezone:"America/Atikokan" }}

{% timezone "America/Panama" %}
    Panama time: {{ value }}
{% endtimezone %}

How can you see all available time zones?

pytz provides helpers, including a list of current time zones and a list of all available time zones – some of which are only of historical interest.

List of timezones from wikipedia: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

Related