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?

6
  • What do you mean by "my laptop"? Is that the server, or the client? May 17, 2017 at 9: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, 2017 at 9:43
  • Did you read the comprehensive documentation on setting the user's timezone in Django? May 17, 2017 at 9: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, 2017 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. May 17, 2017 at 10:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.