I have a Python CGI program which prints datetime values. The timestamps are all formatted to the server’s time which is way off from the local time of some of the users. How can I format it automatically for all users based on their time zone?
Here is one of the formatted string:
2011-09-25 02:04:54
That string was created by using a datetime.datetime object.
-Sunjay03
You will have to have a way to find the timezone of the user. One way to do this is by having them set it in a preference page, and storing it in the database, and looking it up when you render the page. Another way is to have the browser include its current time in the request, so that you can adjust your times.
One you know the user’s offset from your server time, you can use
timedeltamethods to adjust the datetime object.