Tuesday, May 1, 2012

Re: Django timezone doesn't show the right time?

On Apr 30, 11:03 pm, Dan Santos <dansanto...@gmail.com> wrote:
> Hi I'm a total programming newbie!
>
> ### INTRO ###
> I have been following this tutorial and the timezone outputs confuses
> me.https://docs.djangoproject.com/en/1.4/intro/tutorial01/#playing-with-...
>
> And I'm still confused after reading these explanations, I basically
> need some really dumbed down answers to understand this timezone
> business:
>
> <b>TIME_ZONE setting: How does it work?</b>http://groups.google.com/group/django-users/browse_thread/thread/bebb...
>
> ### QUESTION ###
> * Europe/Brussels has UTC+2 during summer time.
>
> When I run this as I follow the Django tutorial, then the time (20:34)
> is behind by 2 hours to my local time and UTC displays +00:00.
> Shouldn't it display 22:34 +02:00 instead for a server located at
> Europe/Brussels?
>
> >>> Poll.objects.all()
>
> <Poll: How do you do? 2012-04-26 20:34:33.337247+00:00>]

Internally Django works in UTC . When you display a value in a
template or in a form it will be converted to the currently active
time zone (by default settings.TIMEZONE). So, when you just do
Poll.objects.all() you will see the UTC time, as this is Python
internal representation. If you would do {{poll.pub_date}} in the
template, it would be displayed in the time zone you have currently
active.

- Anssi

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment