2014-12-11 18 views

回答

0

使用datetime模块这一点。

使用datetime.datetime.strptime将字符串转换为日期,然后使用>=进行比较。

0
import time 
from time import gmtime, strftime 
currentTime=strftime("%Y-%m-%d %H:%M:%S", gmtime()) 
print currentTime 
time.sleep(5) 
SecondTime=strftime("%Y-%m-%d %H:%M:%S", gmtime()) 
print SecondTime 
from dateutil.parser import parse 
parseSecondTime = parse(SecondTime) 
parseCurrentTime = parse(currentTime) 
diffOfTime = parseSecondTime - parseCurrentTime 
timeDifference=diffOfTime.total_seconds() 
print timeDifference 
if timeDifference>0: 
    print 'SecondTime is greater' 
else: 
    print 'Current Time is Greater'