2

The user has entered a time and we are saving it in UTC. We would like to display this time back to the user using the template language after submission, in their own time zone.

4

2 回答 2

3

您可以使用以下方法localtime

{% load tz %}

{% localtime on %}
    {{ value }}
{% endlocaltime %}

{% localtime off %}
    {{ value }}
{% endlocaltime %}
于 2013-08-06T20:04:13.527 回答
0

您需要自己确定用户的时区。然后,您可以这样做:

{% load tz %}
{% timezone "Europe/Paris" %}
    Paris time: {{ object.date }}
{% endtimezone %}
于 2018-05-26T19:17:30.463 回答