描述:给出两个可识别的日期,计算出两个日期间隔天数
输入:str1,str2 格式均为YYYY/MM/DD,如2013/08/06,入参合法性无需验证
返回:int类型,并有正负数,当str1表达日期在str2之前返回值为小于0
import datetime
class Demo:
def intervalDays(self,str1,str2):
list1 = str1.split('/')
year1 = int(list1[0])
mon1 = int(list1[1])
day1 = int(list1[2])
list2 = str2.split('/')
year2 = int(list2[0])
mon2 = int(list2[1])
day2 = int(list2[2])
date1 = datetime.datetime(year1,mon1,day1)
date2 = datetime.datetime(year2,mon2,day2)
interval = (date1 - date2).days
return interval
Test = Demo()
str1 = raw_input('Please Input a data(like:xxxx/xx/xx): ')
str2 = raw_input('Please Input a data(like:xxxx/xx/xx): ')
print Test.intervalDays(str1,str2)