您好!欢迎来到聚码网

聚码网

热门搜索: 相亲小程序    搭子源码    直播系统自有商城   
  • python-关于计算日期的问题
  • 聚码交流
  • 0 1
  • yhuxAvNbtxUM
    0000-00-00 00:00:00
  • 回帖
先上代码defget_date(today,num):try:myday=datetime.datetime(int(today[0:4]),int(today[5:7]),int(today[8:10]))+datetime.timedelta(days=num)dt=myday.strftime('%Y-%m-%d')exceptExceptionase:print(e)print('日期格式不合法')returnreturndtif__name__=='__main__':print('计算日期列表...')date_list=[]today='2017-06-20'foriinrange(-90,0):date=get_date(today,i)ISOTIMEFORMAT='%Y-%m-%d'tm=time.strptime(date,ISOTIMEFORMAT)iftime.asctime(tm)[0:3]!='Sat'andtime.asctime(tm)[0:3]!='Sun':date_list.append(date)#去除双休日else:printdate,'isholiday,removed..'#date_list就是日期列表计算的是2017-6-20之前90天除了双休日之外的所有日期,有谁有更简单暴力的方法吗?第三方库推荐下也行。
最近热帖
近期热议
联系我们
Q Q:317563994
电话:400-000-000
邮箱:317563994@qq.com
时间:09:00 - 17:00