2014-12-11 51 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'