python---时间计算

import time, datetime
from dateutil.parser import parse

date1 = '2017-10-01 12:12:12'
date2 = '2013-3-4 10:10:10'

aa = time.mktime(time.strptime(date1, "%Y-%m-%d %H:%M:%S"))
bb = time.mktime(time.strptime(date2, "%Y-%m-%d %H:%M:%S"))
print(aa)
print(bb)
print(aa-bb)

a = parse(date1)
b = parse(date2)
print((a-b).days)
print((a-b).seconds)
print((a-b).total_seconds())
print(type(datetime.datetime.now().time().hour))



输出结果:

python---时间计算_第1张图片

 

 

你可能感兴趣的:(python语法,python)