Discussion:
In my django web app i wannt show time in user timezone
Deniz Bazan
2018-12-07 22:46:51 UTC
Permalink
Hello everybody,
I have a django web app, in my app i want to show in the page where the
time information is, with user timezone.

I have a form with start_time and end_time(Timefield) user send this with a
specific timezone(Berlin/Europa) after this when a user go to the page, the
user should see the page with his own timezone.

I use Django 2.1 with postgresql database.

Thanks for any recommendation!
Regards,
Deniz
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e727995f-87e8-4a5c-bc25-fbe948269360%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
t***@gmail.com
2018-12-08 04:02:33 UTC
Permalink
Hello,
I think you can use "request.META" django. (request.META['TZ']). It is
timezone user submit request.

:D
Post by Deniz Bazan
Hello everybody,
I have a django web app, in my app i want to show in the page where the
time information is, with user timezone.
I have a form with start_time and end_time(Timefield) user send this with
a specific timezone(Berlin/Europa) after this when a user go to the page,
the user should see the page with his own timezone.
I use Django 2.1 with postgresql database.
Thanks for any recommendation!
Regards,
Deniz
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/eaa47d65-8bd5-4a9d-95a4-28bc5761317c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Vovk Donets
2018-12-08 07:01:19 UTC
Permalink
From docs: "...there’s no equivalent of the Accept-Language HTTP header
that Django could use to determine the user’s time zone automatically.
Instead, Django provides time zone selection functions
<https://docs.djangoproject.com/en/dev/ref/utils/#time-zone-selection-functions>.
Use them to build the time zone selection logic that makes sense for you."

There is two paths.
First. You can store time on the server in UTC, detect user timezone and
then do conversion to this timezone on your backend. You can also look at
https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#localtime
Second path is that you can do time conversion on the frontend using
whatever you like JS library to do this work. But in both cases you should
determine users timezone yourself or ask user in which TZ he is.
Post by t***@gmail.com
Hello,
I think you can use "request.META" django. (request.META['TZ']). It is
timezone user submit request.
:D
Post by Deniz Bazan
Hello everybody,
I have a django web app, in my app i want to show in the page where the
time information is, with user timezone.
I have a form with start_time and end_time(Timefield) user send this with
a specific timezone(Berlin/Europa) after this when a user go to the page,
the user should see the page with his own timezone.
I use Django 2.1 with postgresql database.
Thanks for any recommendation!
Regards,
Deniz
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/eaa47d65-8bd5-4a9d-95a4-28bc5761317c%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/eaa47d65-8bd5-4a9d-95a4-28bc5761317c%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
*Vovk Donets*
python developer
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPTMM-wAYdM2q%3DdQjaBZNvdbBX6DANkHYSqaW4%3DDambBN9WeaA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Deniz Bazan
2018-12-08 16:26:57 UTC
Permalink
Hello Vovk Donets,
thanks for your answer.

In my app, i can not ask the user for timezone because its impossible.I
send a screen shot from app you can better understand me.

[image: image.png]
this is for a Internet TV.The user can be from any timezone.
I want just use django(python) make this possible.
In your answer you say there is two way make this, but i don't understand
1. way(*detect user timezone and then do conversion to this timezone on
your backend. *)


*Settings.py*
TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

*my model.py*
class Guide(models.Model):

episode=models.ForeignKey(Episode,on_delete=models.CASCADE,verbose_name=_('Program'))
slug=models.SlugField(max_length=100 ,unique=True,allow_unicode=True)

create_date=models.DateField(default=timezone.now,verbose_name=_('Publishing
Date'))
start_time=models.TimeField(default=timezone.now,verbose_name=_('Start
Time'))
end_time=models.TimeField(default=timezone.now,verbose_name=_('End
Time'))
publish=models.BooleanField(default=True,verbose_name=_('Publish'))

i use in time field *default=timezone.now *but i m not sure* i*f should use
*default=datetime.datetime.now*
Post by Vovk Donets
From docs: "...there’s no equivalent of the Accept-Language HTTP header
that Django could use to determine the user’s time zone automatically.
Instead, Django provides time zone selection functions
<https://docs.djangoproject.com/en/dev/ref/utils/#time-zone-selection-functions>.
Use them to build the time zone selection logic that makes sense for you."
There is two paths.
First. You can store time on the server in UTC, detect user timezone and
then do conversion to this timezone on your backend. You can also look at
https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#localtime
Second path is that you can do time conversion on the frontend using
whatever you like JS library to do this work. But in both cases you should
determine users timezone yourself or ask user in which TZ he is.
Post by t***@gmail.com
Hello,
I think you can use "request.META" django. (request.META['TZ']). It is
timezone user submit request.
:D
Post by Deniz Bazan
Hello everybody,
I have a django web app, in my app i want to show in the page where the
time information is, with user timezone.
I have a form with start_time and end_time(Timefield) user send this
with a specific timezone(Berlin/Europa) after this when a user go to the
page, the user should see the page with his own timezone.
I use Django 2.1 with postgresql database.
Thanks for any recommendation!
Regards,
Deniz
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/eaa47d65-8bd5-4a9d-95a4-28bc5761317c%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/eaa47d65-8bd5-4a9d-95a4-28bc5761317c%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
*Vovk Donets*
python developer
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAPTMM-wAYdM2q%3DdQjaBZNvdbBX6DANkHYSqaW4%3DDambBN9WeaA%40mail.gmail.com
<https://groups.google.com/d/msgid/django-users/CAPTMM-wAYdM2q%3DdQjaBZNvdbBX6DANkHYSqaW4%3DDambBN9WeaA%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
Mit freundlichen GrÌßen
*Deniz Bazan*

Web Entwickler
Filmmaker, Cutter, 3D Artist
Tel:+49 163 133 68 00
http://denizbazan.jimdo.com
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADVVM_i7BedKJP8z08hz-5u9Ed16HshG2QvHXdG3Mg5fc5C%3DBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...