Monday, August 31, 2015

Re: TIME ZONE DJANGO SAVE DATETIMEFIELD

No doubt that django is acting correctly. I understand what you tell me about it, then I know I can do conversions to the date shown in the templates have my time zone, but it is not what I want. Because when I do queries on bills for closing Z does not work, even when I have to close and tell me which corresponds to another day. by the same gap that you commented.
If you do the cierreZ day: 2015/08/30 19:00 (client time), with the gap that I have tells me the date is 2015/08/31 1:00 (server time), that is already being done the next day, which is incorrect.

Ah, excuse my English.

El lunes, 31 de agosto de 2015, 16:39:16 (UTC-4:30), James Schneider escribió:
> Hello is the first time I write on the list, I have little time learning
> Django and presented me a drawback. I have a model called Bill, which has a
> field called date of sale, and I need to store the date and time of the sale
> but the client time, and now it is keeping the server time. As I keep the
> date and time correctly in the model?
> I have some variables in established settings:
>
> USE_TZ = True
> TIME_ZONE = 'America / Caracas'
>
> /********************models.py   ***********/
>
> class Factura(models.Model):
>       fecha = models.DateTimeField()

Have you validated that the time being stored is incorrect? I'm
willing to bet that the date and time in the database is actually
being stored in UTC, but the output in the templates is being
displayed with the undesired offset. Check out this page on handling
output of DateTime fields:

https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/#time-zone-aware-output-in-templates

https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/#default-time-zone-and-current-time-zone

Actually that whole page is a good read. Basically you need to ensure
that your DateTime is being saved in UTC (or at the very least,
everything being stored has an offset attached to it so that the
correct date/time/timezone can be calculated). Django is probably
already doing that, but you'll need to set the current time zone for a
particular user so that the templates output the right DateTime.

-James

--
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+unsubscribe@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/1846089f-cca9-4f4c-9399-7dc376fe3d2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment