0

I have template which displays the time sent from the view. views.py contains following code

from datetime import datetime
from django.utils import timezone
def func(request): 
    now=datetime.utcnow()
    timezone.activate('Asia/Kolkata')
    return render(request,'time.html',{'time':now})

This will display the time in time zone 'Asia/Kolkata'. Now the time zone is set by me. I want to set the current timezone to my laptop's timezone.

That is i want the timezone to change with my laptop's timezone. I have tried to read system timezone but all method give the django's current timezone set by activate ( Here 'Asia/Kolkata' ).

Will you please help me?

vishnu m c
  • 841
  • 1
  • 7
  • 21
  • What do you mean by "my laptop"? Is that the server, or the client? – Daniel Roseman May 17 '17 at 09:01
  • client itself. I will give you an example, consider using whatsapp over website. when i change my laptop's time zone, the resulting messages are shown in the current timezone of my laptop. Just like that – vishnu m c May 17 '17 at 09:43
  • Did you read the [comprehensive documentation](https://docs.djangoproject.com/en/1.11/topics/i18n/timezones/#selecting-the-current-time-zone) on setting the user's timezone in Django? – Daniel Roseman May 17 '17 at 09:48
  • Yes i have read it. So you are trying to say that there is no way to do? In the document, it is showed that manually selecting the timezone. – vishnu m c May 17 '17 at 10:09
  • The point is, as that doc shows, the timezone is simply not sent in the request from the browser to the server. So the only way to set it automatically per user is for the user first to choose which timezone they want, and store that in the database or the session. – Daniel Roseman May 17 '17 at 10:11
  • So it is not possible to do as i said. Ok can we think, if we can read the timezone of client's laptop, we can activate the django current timezone to the same instead of allowing the user to select. – vishnu m c May 17 '17 at 10:37

0 Answers0