Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display localized time from datetime in django template

To be brief. next_contact is a UTC datetime When I write in template

{{ event.next_contact }}

I get properly localized date and time But in this place I want output only time so I do:

{{ event.next_contact.time }}

and then I get non localized time

How to fix it??

like image 822
Lord_JABA Avatar asked Jun 27 '14 09:06

Lord_JABA


1 Answers

Use {{ event.next_contact|localtime|date:"H:i" }}. If you have set USE_TZ=True you can skip the localtime filter.

As of Django 1.7 when passed a datetime value with attached timezone information (a time-zone-aware datetime instance) the time filter will accept the timezone-related format specifiers 'e', 'O' , 'T' and 'Z'.

like image 78
Martin Avatar answered Sep 19 '22 10:09

Martin