View Single Post
Old Jan 26th, 2006, 6:36 PM   #3
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,827
Rep Power: 5 Sane will become famous soon enough
Wee. I decided to try it out myself.

time.gmtime() will convert the seconds since epoch to a date. So if we take the current seconds since epoch time.time() and offset it back a day, voila!

import time

def time_zone( offset = 0 ): # DEFAULT = GMT
    new = time.gmtime( time.time() + offset*60*60 )
    return "Day: %s | Month: %s | Year: %s\n%s:%s:%s"%(new[2],new[1],new[0],new[3],new[4],new[5])

print time_zone( -5 )

I'm -5 from GMT, so if I then set it to -29, it gives me yesterday's date.

Hope this helps. =D
Sane is offline   Reply With Quote