In my django project\'s settings.py
file, I have this line :
TIME_ZONE = \'UTC\'
But I want my app to run in UTC+2 timezone, s
Change the TIME_ZONE to your local time zone, and keep USE_TZ as True in 'setting.py':
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
This will write and store the datetime object as UTC to the backend database.
Then use template tag to convert the UTC time in your frontend template as such:
{% load tz %}
{% get_current_timezone as tz %}
{% timezone tz %}
{{ message.log_date | time:'H:i:s' }}
{% endtimezone %}
or use the template filters concisely:
{% load tz %}
{{ message.log_date | localtime | time:'H:i:s' }}
You could check more details in the official doc: Default time zone and current time zone
When support for time zones is enabled, Django stores datetime information in UTC in the database, uses time-zone-aware datetime objects internally, and translates them to the end user’s time zone in templates and forms.