2014-08-30 16:00:00+00:00 GMT
2014-08-30 12:00:00-04:00 Toronto (Summer)
This looks correct to me.  Maybe you were expecting the
timezone to be -05:00?  That would be standard time (winter).
Daylight savings time is -04:00.

--

Geoffrey S. Knauth | [1]http://knauth.org/gsk



On Wed, Aug 20, 2014, at 08:22, christophw wrote:

Hi there,

I'm feeling some pain while wrangling with timezones in an
office room booking application.  I'm storing bookings in a
MySQL database and want to display them in the timezone local
to the office room, so it is not necessarily local to the
user's local machine timezone.

Here is my model's datetime definition:
classBooking(models.Model):
 date_time = models.DateTimeField()

When the booking is stored, it comes back from a post and I
store it in the DB as such:

dt = datetime.datetime.strptime(request.POST["date"]+" "+
request.POST["time"],"%Y-%m-%d %H:%M")
dt = pytz.timezone("America/Toronto").localize(dt)

Printing the value of dt after that call, it looks correct.

Later on, I pull that booking out of my database by ID and
render it in my template, rendering the datetime like this:

<small>{{booking.date_time}}</small>

I've tried re-interpreting the timezone after pulling it out of
the database, to no avail. When I print the datetime object
directly after it is pulled out of MySQL, I get it in UTC like
so:
2014-08-3016:00:00+00:00

Re-interpreting it to force it into the office's local
timezone, I get the correct result but 1 hour off is still
rendered in the web browser

# returns 2014-08-30 12:00:00-04:00
booking.date_time =
pytz.timezone("America/Toronto").normalize(booking.date_time)



The result of this is the time is rendered 1 hour behind the
actual time.  This is consistent across all datetimes I've
tried, and I seem to be unable to get Django to render the
correct time.

My question is this: Why is my datetime consistently rendering
1 hour off, and how do I wrangle it into rendering at the true
time?

--

You received this message because you are subscribed to the
Google Groups "Django users" group.

To unsubscribe from this group and stop receiving emails from
it, send an email to
[2]django-users+unsubscr...@googlegroups.com.

To post to this group, send email to
[3]django-users@googlegroups.com.

Visit this group at
[4]http://groups.google.com/group/django-users.

To view this discussion on the web visit
[5]https://groups.google.com/d/msgid/django-users/2dbd562a-5db3
-4787-80d2-5a0f93f07860%40googlegroups.com.

For more options, visit [6]https://groups.google.com/d/optout.

References

1. http://knauth.org/gsk
2. mailto:django-users+unsubscr...@googlegroups.com
3. mailto:django-users@googlegroups.com
4. http://groups.google.com/group/django-users
5. 
https://groups.google.com/d/msgid/django-users/2dbd562a-5db3-4787-80d2-5a0f93f07860%40googlegroups.com?utm_medium=email&utm_source=footer
6. https://groups.google.com/d/optout

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1408537967.3259961.154775081.30E70C64%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to