![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 | |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Quote:
in a few days I would have seen this. Now I have to add some string processing to remove the leading zero. Arevos, you are a genius!
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
|
#12 |
|
Newbie
Join Date: Jan 2006
Posts: 13
Rep Power: 0
![]() |
Bingo. Thanks very.
|
|
|
|
|
|
#13 |
|
Programming Guru
![]() ![]() |
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 timeConverting 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. |
|
|
|
|
|
#14 | |
|
Programmer
Join Date: Apr 2005
Posts: 73
Rep Power: 4
![]() |
Quote:
import time
def timestr_to_epoch(timestr):
localtime = time.strptime(timestr, "%a %b %d %H:%M:%S %Y")
return time.mktime(localtime)
print timestr_to_epoch(time.ctime())
print time.time() |
|
|
|
|
|
|
#15 |
|
Programming Guru
![]() ![]() |
Thanks. I wonder which is faster though.
![]() |
|
|
|
|
|
#16 | |
|
Programmer
Join Date: Apr 2005
Posts: 73
Rep Power: 4
![]() |
Quote:
import this *(If you have to process millions of dates in one go, and must have the speed, then yes, a hand-rolled problem-specific solution such as yours may be necessary. If you don't, the fraction of a second advantage is outweighed by the other factors) |
|
|
|
|
|
|
#17 |
|
Programming Guru
![]() ![]() |
Well not necessary "millions", but every forum they visit, every topic must have its last post's date converted to epoch to be compared with the user's last visit.
I had to do it awkwardly like this, because I forgot to incorporate new posts in to my forums when I was first programming them. But adding this in didn't change the speed of the forums noticably at all. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|