Santhosh
Santhosh

Reputation: 11834

django: template show timezone also for the datetime

I am sending the following datetime timezone aware object to django template

current_time = timezone.now()

In my template i am showing it using

{{ current_time }}

it displays as:

Feb. 10, 2021, 3:25 a.m

I want it to display as

Feb. 10, 2021, 3:25 a.m UTC

I dont see which timezone the time is. So i want to be more clear by adding the timezone.

how can i do this in django template

Upvotes: 1

Views: 308

Answers (1)

Max
Max

Reputation: 876

try this

{{ current_time |date:"b d Y f a T" }}
  • b:Month, textual, 3 letters, lowercase. 'jan'
  • d:Day of the month, 2 digits with leading zeros. '01' to '31' Y:Year, 4 digits. '1999'
  • f:Time, in 12-hour hours and minutes, with minutes left off if they’re zero. Proprietary extension.
  • a:'a.m.' or 'p.m.' (Note that this is slightly different than PHP’s output, because this includes periods to match Associated Press style.) 'a.m.'
  • T:Time zone of this machine. 'EST', 'MDT'

you can see more about date template on here:https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#date

Upvotes: 1

Related Questions