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.
you are probably looking for
time.localtime(seconds). gmtime always returns utc time.