频道栏目
首页 > 资讯 > 其他 > 正文

python 两日期间的天数(计算机科学导论)

18-07-30        来源:[db:作者]  
收藏   我要投稿
def daysBetweenDates(year1, month1, day1, year2, month2, day2):
 def daysinyear(year,month,day):#the day of this year
  count=0
  if year%400==0 or (year%100!=0 and year%4==0):
daysOfMonths1 = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(month-1):
 count += daysOfMonths1[i]
return count + day
  else:
daysOfMonths2 = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(month-1):
 count += daysOfMonths2[i]
return count + day  
 import calendar
 def daysofyear(year1,year2):# the day of (year2-year1)
  minusyearsdays=(year2-year1)*365+calendar.leapdays(year1,year2)
  return minusyearsdays
 total = daysinyear(year2, month2, day2)-daysinyear(year1, month1, day1)+daysofyear(year1,year2)
 return total
  

计算两不同日期间的天数 难点在于每月日期不同 存在平年闰年 借鉴了其他大神的日期函数 将年份和月份拆开分别计算天数再进行求和运算

相关TAG标签
上一篇:VMware Workstation虚拟机上新安装的centos 7系统链接网络的方法
下一篇:浅谈继承的特性
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站