Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7749843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:08:20+00:00 2026-06-01T11:08:20+00:00

[Edit] And, I should add, most elegantly? I guess (but not sure how) I

  • 0

[Edit] And, I should add, most elegantly? I guess (but not sure how) I could just loop through the results in the python code first and format each date there, but I’d rather only loop once…[\Edit]

In my case British Summer Time (which has just recently kicked in).

At the moment my topmost directly formated date is correct, but the dates in the individual rows of the result are still in UTC (1 hour behind). Example output is a templated page that looks like this (where UTC as returned by datetime.now in this case is 12:42):

Time is now: 13:42 on 05 April, 2012

2012-04-05 13:10:00 Event 234

2012-04-05 13:10:00 Event 235

2012-04-05 13:10:00 Event 236

…

Here’s what I’m doing…

from pytz.gae import pytz  # N.B. Using the recommended version of pytz
from datetime import datetime

# Use datetime now (in UTC) to select upcoming events (also stored in UTC)

nowat = datetime.now()
upcoming_events = db.GqlQuery(
  "SELECT * FROM Event WHERE eventdatetime >= :1",nowat)

# Convert time to BST and print to string…

utc = pytz.timezone('UTC')
nowat = utc.localize(nowat)
bst = pytz.timezone('Europe/London')
timenow = nowat.astimezone(bst).strftime("%H:%M on %d %B, %Y")

# Pass results to template for formating… (this is the Django engine)

template_values = {
        'time' : timenow,
        'events' : upcoming_events
 }
path = os.path.join(os.path.dirname(__file__),'html','today.html')
self.response.out.write(template.render(path,template_values))

I thought there might be some magic I could similarly apply in the templating code – but it only seems that the date built-in allows formating of the datetime NOT conversion from UTC.

Template is:

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/css/main.css" />
  </head>
  <body>
    <p>Time is now: {{ time }}</p>
    <table>
      {% for event in events %} 
        <tr>
          <td> {{ event.eventdatetime }} </td>
          <td> {{ event.name }} </td>
        </tr>
      {% endfor %}  
    </table>
  </body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:08:21+00:00Added an answer on June 1, 2026 at 11:08 am

    with django’s template engine, you can use Time zone aware output in templates

    example usage from the documentation:

    {% load tz %}
    
    {% timezone "Europe/Paris" %}
        Paris time: {{ value }}
    {% endtimezone %}
    
    {% timezone None %}
        Server time: {{ value }}
    {% endtimezone %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: solved it, turns out I should use %c not %s because foodSelect and
Author post-edit: Chosen solution (Original question remains below this box) SUMMARY: You SHOULD NOT
I'm trying to do something that should be very common: add/edit a bunch of
EDIT: When should and shouldn't you break away from OOP for speed/performance? might be
EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been
EDIT: My main code no longer works, should this function work? <script type=text/javascript src=jquery-1.7.2.js></script>
edit: I use version 1.6.8 of jOOQ; in newer versions this should work (see
within my App it should be forbidden to edit (customize) the TabBar. This means
If page has .pdf files linked then a message in <p> should be add
In terms of best/most common practices for programming, where should code go that prevents

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.