Python日期计算

1、将字符串转换成date
nowDate = time.strptime('2010-05-27', "%Y-%m-%d")

2、获取年、月、日
year = nowDate[0]
month  = nowDate[1]
day  = nowDate[2]

3、日期想减,计算天数
d1 = datetime.datetime(2005, 2, 16)
d2 = datetime.datetime(2004, 12, 31)
days = (d1 – d2).days

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