Search code examples
djangotimezoneutcpytz

How to manage timezones in a web application?


I wan't to manage the different timezones of my users in my web application, but I have no idea where to start. I have to save the local time of each user in my database?, or maybe make the conversion to a UTC time, save it, and then make the conversion again to show it?, or there is another way? For example, if one of my users make an appointment in his local time, I have to convert it to UTC store it in my database, and then when he need it, convert it again to his local time an show it?? By the way, I'm using Django. Thanks.


Solution

    1. Store date/time as UTC (Not sure what the Python command for that is)

    2. When outputting dates, wrap them in a helper function that gets the current user's time zone preference, then adjust the time/date for the offset, then output it from the application.

    http://docs.python.org/library/time.html

    http://docs.python.org/library/datetime.html