Reputation: 45
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.
Upvotes: 1
Views: 106
Reputation: 75609
Set time.timezone
to the user's timezone, then display it using localtime().
Upvotes: 0
Reputation: 61437
you are probably looking for time.localtime(seconds)
. gmtime always returns utc time.
Upvotes: 1