这两天在网上看到了一道求两个日期间相隔天数的题目,想到了一个实现的方法:
import time time1 = raw_input("Please input time1:") time2 = raw_input("Please input time2:") timeStamp1 = int(time.mktime(time.strptime(time1,"%Y-%m-%d"))) timeStamp2 = int(time.mktime(time.strptime(time2,"%Y-%m-%d"))) diff = abs(timeStamp1 - timeStamp2) print diff/24/60/60