View Single Post
Old Mar 7th, 2006, 8:02 PM   #9
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,076
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
I was wondering if there was an easier way to do the following:

from time import ctime, mktime, time

def ctime_to_epoch(ctime):
    x1 = ctime.split(' ')
    x2 = x1[3].split(':')
    localtime = (int(x1[-1]),
                 {"Jan":1,"Feb":2,"Mar":3,"Apr":4,
                  "May":5,"Jun":6,"Jul":7,"Aug":8,
                  "Sep":9,"Oct":10,"Nov":11,"Dec":12}[x1[1]],
                 int(x1[2]),int(x2[0]),int(x2[1]),int(x2[2]),0,0,0)
    return mktime(localtime)

ctime = ctime()
time = time()

print ctime_to_epoch(ctime)
print time

Converting a ctime literal back to seconds since epoch. I need to take forum post times and determine which posts are new by converting post times to epoch and comparing it to the epoch of his/her last visit.
Sane is offline   Reply With Quote