tags:

views:

28

answers:

2

Hi,

I'm developing a web application and would like to display user's current date basing on his timezone. Here is my code:

userTimezone = -5 #EAST is positive, WEST negative 
utcTimestamp = time.mktime(time.gmtime())
userDate = time.gmtime(utcTimestamp+userTimezone*60*60)

I think the problem is with gmtime() since it does some conversions automatically. If I could, I would replace gmtime with function which doesn't convert anything, but haven't found any.

+1  A: 

you are probably looking for time.localtime(seconds). gmtime always returns utc time.

Femaref
It should work properly, but when I print time.gmtime() and userDate from my script the difference between these 2 dates is 6 hours, not 5. Also time.altzone on my computer is wrong.
Mateusz Cieslak
Finally it worked. Thank you.
Mateusz Cieslak
A: 

Set time.timezone to the user's timezone, then display it using localtime().

Sjoerd
Is it possible to set time.timezone? It doesn't work.
Mateusz Cieslak