import time
start = time.clock()
time.sleep(5)
end = time.clock()
runtime = end - start
import time
time.asctime()
import time
time.strptime('28/Jul/2013:04:33:29', '%d/%b/%Y:%X')
import time
time.strftime('%Y%m%d %H:%M:%S')
>>> time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
'2015-03-25 13:49:24'
import datetime
(datetime.datetime.now() - datetime.timedelta(days = 100)).strftime("%Y-%m-%d")
import time
time.striptime(string, "%Y-%m-%d %H:%M:%S")
t1 = '2015-03-23 19:04:37'
t2 = '2015-03-21 15:04:37'
dt1 = datetime.strptime(t1, "%Y-%m-%d %H:%M:%S")
dt2 = datetime.strptime(t2, "%Y-%m-%d %H:%M:%S")
d = dt1 - dt2
days = d.days
seconds = d.seconds%60
minutes = (d.seconds/60)%60
hours = (d.seconds/3600)%24
from datetime import *
def calTimeDelay(t1, t2, strip="%Y-%m-%d %H:%M:%S"):
d = abs(datetime.strptime(t2, strip) - datetime.strptime(t1, strip))
days = d.days
seconds = d.seconds%60
hours = (d.seconds/3600)%60
minutes = (d.seconds/60)%60
return days,hours,minutes,seconds
t1 = "2015-03-23 19:04:37"
t2 = "2015-03-21 13:04:37"
print calTimeDelay(t1, t2)